谁能解释一下AES/CBC/PKCS5Padding使用弹跳加密解密
城堡我自己努力尝试,但我没有取得任何成功。
在网上我没有得到关于这个的教程
最佳答案
我假设您询问的是 J2ME 版本中的 Bouncy CaSTLe 轻量级 API。来自specifications page ,有一个如何使用 API 的示例。我已经更新它以匹配最新的 API。 (请注意,我还没有尝试运行它。)
BlockCipher engine = new AESEngine();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine));
byte[] key = keyString.getBytes();
byte[] input = inputString.getBytes();
cipher.init(true, new ParametersWithIV(new KeyParameter(key), ivBytes));
byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
int outputLen = cipher.processBytes(input, 0, input.length, cipherText, 0);
try
{
cipher.doFinal(cipherText, outputLen);
}
catch (CryptoException ce)
{
System.err.println(ce);
System.exit(1);
}
请注意,PaddedBufferedBlockCipher
的默认填充模式是 PKCS7/PKCS5。
解密是类似的,但你会调用cipher.init(false, ...)
并将密文传递给processBytes
。
关于java - 黑莓中的弹跳城堡 aes 加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4343429/