cancel
Showing results for 
Search instead for 
Did you mean: 

User adapter module for PGP encryption using Bouncycastle API

Former Member
0 Kudos

Hello, I'm using the Bouncycastle 1.46 API for encrypting payload. I'm able to encrypt the payload but am having difficulty in armoring (converting the encrypted text to ASCII) and subsequently convert the armored output stream to a Byte Array. I'm converting to byte array so that the module data can be updated with the encrypted & armored payload.

The code looks as follows:

//Define an armored output stream

OutputStream out = null;

ByteArrayOutputStream oBAOS = new ByteArrayOutputStream();

out = new ArmoredOutputStream(oBAOS);

//bOut is the ByteArrayOutputStream from the Encryptor (available after encryption)

byte[] bytes = bOut.toByteArray();

//cPk is the object of PGPEncryptedDataGenerator

                              OutputStream ByteOut = cPk.open(out, bytes.length);

                              ByteOut.write(bytes);

//Get the encrypted and armored payload from ByteOut OutputStream

payload.setContent(ByteOut.toByteArray());

                              inputModuleData.setPrincipalData(msg);

I'm unsure if what I've coded in the lines highlighted in bold is correct. If I execute the code as a bean or as a sample application, I'm not getting any error nor the desired result. Any input is appreciated!

Thanks!!

Accepted Solutions (0)

Answers (1)

Answers (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

Never used Bouncycastle 1.46 API,

Have you tested your code in stand alone system(NWDS or eclipse)better to test then convert in to Adaptyer module,i hope the you have genarated EAR file with additional JAR files(used in your code).

Former Member
0 Kudos

I am testing the code in Eclipse as a standalone application. The approach I've taken is available in the URL http://stackoverflow.com/questions/3939447/how-to-encrypt-a-string-stream-with-bouncycastle-pgp-with...

I'm having trouble in converting the encrypted ByteArrayOutputStream into ArmoredOutputStream (a part of Bouncycastle API and implements OutputStream) and subsequently convery the ArmoredOutputStream back to a Byte Array. This Byte Array will eventually have to be used to update inputModuleData object in the User Adapter Module