Search in sources :

Example 1 with JcePBEKeyEncryptionMethodGenerator

use of org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator in project camel by apache.

the class PGPDataFormatTest method testExceptionDecryptorIncorrectInputFormatSymmetricEncryptedData.

@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.");
}
Also used : JcePBEKeyEncryptionMethodGenerator(org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) BCPGOutputStream(org.bouncycastle.bcpg.BCPGOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) PGPCompressedDataGenerator(org.bouncycastle.openpgp.PGPCompressedDataGenerator) SecureRandom(java.security.SecureRandom) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PGPLiteralDataGenerator(org.bouncycastle.openpgp.PGPLiteralDataGenerator) BufferedOutputStream(java.io.BufferedOutputStream) PGPEncryptedDataGenerator(org.bouncycastle.openpgp.PGPEncryptedDataGenerator) Date(java.util.Date) JcePGPDataEncryptorBuilder(org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder) Test(org.junit.Test)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 SecureRandom (java.security.SecureRandom)1 Date (java.util.Date)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 BCPGOutputStream (org.bouncycastle.bcpg.BCPGOutputStream)1 PGPCompressedDataGenerator (org.bouncycastle.openpgp.PGPCompressedDataGenerator)1 PGPEncryptedDataGenerator (org.bouncycastle.openpgp.PGPEncryptedDataGenerator)1 PGPLiteralDataGenerator (org.bouncycastle.openpgp.PGPLiteralDataGenerator)1 JcePBEKeyEncryptionMethodGenerator (org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator)1 JcePGPDataEncryptorBuilder (org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder)1 Test (org.junit.Test)1