【发布时间】:2012-11-06 23:25:14
【问题描述】:
我通过 java 实现这个,BouncyCastle Provider 使用 Block mode = ECB 和 Padding mode = PKCS7Padding
I noticte that if i encrypt data that has 32 byte length(such as 61626162616261626162616261626162 which is hex value of abababababababab) i get 64 bytes length cipher text(f21ee0564ebd5274e10bf4590594b1e16a19592b917b19ee106f71d41d165289) is this cipher text valid?从我读到的内容来看,如果您加密小于 32 字节长度的数据,算法会将其填充为 32 字节长度并生成 32 字节长度的密文,但如果您输入的数据恰好为 32 字节长度,您不应该收到 32字节长度密文,如果我输入长度超过 32 字节的数据,它将正确填充到 64 字节密文
这就是我的代码的样子:
public static byte[] encrypt(byte[] plainText, byte[] keyBytes)
throws GeneralSecurityException {
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText = cipher.doFinal(plainText);
return cipherText;
}
感谢您的回复
【问题讨论】:
标签: java security encryption bouncycastle