Java 类org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator 实例源码

项目:Camel    文件:PGPDataFormatTest.java   
@Test
public void testExceptionDecryptorIncorrectInputFormatSymmetricEncryptedData() throws Exception {

    byte[] payload = "Not Correct Format".getBytes("UTF-8");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5)
            .setSecureRandom(new SecureRandom()).setProvider(getProvider()));

    encGen.addMethod(new JcePBEKeyEncryptionMethodGenerator("pw".toCharArray()));

    OutputStream encOut = encGen.open(bos, new byte[1024]);
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZIP);
    OutputStream comOut = new BufferedOutputStream(comData.open(encOut));
    PGPLiteralDataGenerator litData = new PGPLiteralDataGenerator();
    OutputStream litOut = litData.open(comOut, PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, new Date(), new byte[1024]);
    litOut.write(payload);
    litOut.flush();
    litOut.close();
    comOut.close();
    encOut.close();
    MockEndpoint mock = getMockEndpoint("mock:exception");
    mock.expectedMessageCount(1);
    template.sendBody("direct:subkeyUnmarshal", bos.toByteArray());
    assertMockEndpointsSatisfied();

    checkThrownException(mock, IllegalArgumentException.class, null, "The input message body has an invalid format.");
}
项目:CryptMeme    文件:PGPEncryptedDataGenerator.java   
/**
 * Add a PBE encryption method to the encrypted object.
 *
 * @param passPhrase passphrase to use to generate key.
 * @param s2kDigest digest algorithm to use for S2K calculation
 * @throws NoSuchProviderException
 * @throws PGPException
 * @deprecated  use addMethod that takes  PGPKeyEncryptionMethodGenerator
 */
public void addMethod(
    char[]    passPhrase,
    int       s2kDigest)
    throws NoSuchProviderException, PGPException
{
    if (defProvider == null)
    {
        defProvider = new BouncyCastleProvider();
    }

    addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase, new JcaPGPDigestCalculatorProviderBuilder().setProvider(defProvider).build().get(s2kDigest)).setProvider(defProvider).setSecureRandom(rand));
}
项目:irma_future_id    文件:PGPEncryptedDataGenerator.java   
/**
 * Add a PBE encryption method to the encrypted object.
 *
 * @param passPhrase passphrase to use to generate key.
 * @param s2kDigest digest algorithm to use for S2K calculation
 * @throws NoSuchProviderException
 * @throws PGPException
 * @deprecated  use addMethod that takes  PGPKeyEncryptionMethodGenerator
 */
public void addMethod(
    char[]    passPhrase,
    int       s2kDigest)
    throws NoSuchProviderException, PGPException
{
    if (defProvider == null)
    {
        defProvider = new BouncyCastleProvider();
    }

    addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase, new JcaPGPDigestCalculatorProviderBuilder().setProvider(defProvider).build().get(s2kDigest)).setProvider(defProvider).setSecureRandom(rand));
}
项目:bc-java    文件:PGPEncryptedDataGenerator.java   
/**
 * Add a PBE encryption method to the encrypted object.
 *
 * @param passPhrase passphrase to use to generate key.
 * @param s2kDigest digest algorithm to use for S2K calculation
 * @throws NoSuchProviderException
 * @throws PGPException
 * @deprecated  use addMethod that takes  PGPKeyEncryptionMethodGenerator
 */
public void addMethod(
    char[]    passPhrase,
    int       s2kDigest)
    throws NoSuchProviderException, PGPException
{
    if (defProvider == null)
    {
        defProvider = new BouncyCastleProvider();
    }

    addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase, new JcaPGPDigestCalculatorProviderBuilder().setProvider(defProvider).build().get(s2kDigest)).setProvider(defProvider).setSecureRandom(rand));
}