views:

1907

answers:

3

I am using AES/CBC/PKCS5Padding cipher instance for AES encryption and decryption in java How can I decrypt the data using blackberry encrypted by above in java.

decrypting data with AES/CBC/PKCS5Padding using blackberry

Thanks Bapi

+1  A: 

I think the Bouncy Castle Library supports that. They provide some short tutorials too.

wds
A: 

Bouncy castle has a fantastic library for doing this. The main problem will be how to get the key there in a secure way. I found that .NET and Java serialize the keys in incompatible ways, so I ended up using Bouncy Castle on both sides in order to facilitate key transfer, as it was transferred using RSA, for security sake.

James Black
+3  A: 

I recommend using the BlackBerry API (Bouncy Castle will work, but why complicate things?).

Use the net.rim.crypto package - you're using all symmetric encryption so you'll only need the standard RIM signing keys to run on a device ($20 and 2-3 days to get) - in the meantime you can do everything with the simulator.

Basically you'll want to create a PKCS5UnformatterEngine which wraps a CBCDecryptorEngine which wraps an AESDecryptorEngine. Probably wrap everything in a BlockDecryptor so you can treat is as in InputStream. Something like (and it's been a little while since I've done this, so it may not work 100% as written):

InputStream encryptedInput;  // if you have a byte[] of data, use a ByteArrayInputStream
AESKey key = new AESKey(<your key data as a byte[]>) 
InitializationVector iv = new InitializationVector(<your iv data as a byte[]>) // of course you need to know your IV since you're doing CBC encryption

BlockDecryptor decryptor = new BlockDecryptor(
   new PKCS5UnformatterEngine(
      new CBCDecryptorEngine(
         new AESDecryptorEngine(key),
         iv
      )
   )
);

// then decryptor acts as an InputStream which gives you your decrypted, unpacked data

decryptor.read(buffer); // buffer will contain decrypted, unpacked data
Anthony Rizk
that is a better answer than mine but in my defence I didn't see the blackberry tag till I read yours. :-)
wds