我正在尝试按照此处指定的 CBC 模式步骤,使用内置 ECB Java 实现来实现 AES-CBC 密码。请注意,我不关心我的实现的实际安全性(例如,无填充或使用密钥作为 IV)。
问题是,与使用该站点相比,只有大约部分字节被正确编码PKCS5Padding
。
Key: mvLBiZsiTbGwrfJB
Input: abcdabcdabcdabcd
My result: e9qdKeY1m4OAIsPerfnUi5F35z814ywucLJKKi4rTP8=
Result from site: e9qdKeY1m4OAIsPerfnUi9jNsRJtdELZliFtebuJrrc=
Key: mvLBiZsiTbGwrfJB
Input: abcdabcdabcdabcdabcdabcdabcdabcd
My result: e9qdKeY1m4OAIsPerfnUi5F35z814ywucLJKKi4rTP8=uf5VPLwumm+66ESiQMlKXJF35z814ywucLJKKi4rTP8=
Result from site: e9qdKeY1m4OAIsPerfnUi7I+cPTpraAgZIQvr8OLf7Iu4eKRG1MIcq5yQGsRt3PS
对于NoPadding选项:
Key: mvLBiZsiTbGwrfJB
Input: abcdabcdabcdabcd
My result: e9qdKeY1m4OAIsPerfnUiw==
Key: mvLBiZsiTbGwrfJB
Input: abcdabcdabcdabcdabcdabcdabcdabcd
My result: e9qdKeY1m4OAIsPerfnUiw==uf5VPLwumm+66ESiQMlKXA==
另外,解密根本不起作用,因为PKCS5Padding我有例外:
Exception in thread "main" javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
at java.base/com.sun.crypto.provider.CipherCore.prepareInputBuffer(CipherCore.java:1005)
at java.base/com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:848)
at java.base/com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2202)
at AesEcb.decrypt(AesEcb.kt:27)
at AesEcb.decryptToByteArray(AesEcb.kt:36)
at AesCbcOwn.decrypt(AesCbcOwn.kt:32)
一只斗牛犬
相关分类