bapi
bapi

Reputation:

decrypting data with AES/CBC/PKCS5Padding using blackberry

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

Upvotes: 5

Views: 5833

Answers (3)

Anthony Rizk
Anthony Rizk

Reputation: 3666

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

Upvotes: 5

James Black
James Black

Reputation: 41858

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.

Upvotes: 0

wds
wds

Reputation: 32293

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

Upvotes: 2

Related Questions