使用黑莓AES / CBC / PKCS5Padding解密数据 [英] decrypting data with AES/CBC/PKCS5Padding using blackberry

查看:189
本文介绍了使用黑莓AES / CBC / PKCS5Padding解密数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AES中使用AES / CBC / PKCS5Padding加密实例进行AES加密和解密
我如何使用java中以上加密的黑莓解密数据。



使用黑莓解密AES / CBC / PKCS5Padding数据



感谢
Bapi

解决方案

我建议使用BlackBerry API(Bouncy Castle会工作,但是为什么会使事情变得复杂)?



使用net.rim.crypto包 - 您正在使用所有对称加密,因此您只需要标准的 RIM签名密钥在一个设备上运行($ 20和2-3天) - 同时你可以用模拟器做所有事情。



基本上你将要创建一个PKCS5UnformatterEngine它包装一个封装AESDecryptorEngine的CBCDecryptorEngine。可能将一切封装在BlockDecryptor中,以便您可以像InputStream一样处理。有些东西(和已经有一段时间,因为我这样做,所以它可能无法100%写作):

  AESKey key = new AESKey(<你的密钥数据作为一个字节[]>)
InitializationVector iv = new InitializationVector(<你的iv数据作为一个字节[]>)//当然你需要知道你的IV,因为你正在做CBC加密

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


);

// then解密器充当InputStream,它为您提供解密的解包数据

decryptor.read(buffer); //缓冲区将包含解密的,未打包的数据


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

解决方案

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

这篇关于使用黑莓AES / CBC / PKCS5Padding解密数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆