decrypting data with AES/CBC/PKCS5Padding using blackberry

三世轮回 提交于 2019-12-10 15:43:22

问题


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:


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



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/901251/decrypting-data-with-aes-cbc-pkcs5padding-using-blackberry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!