as3加密问题
我正在使用 as3crypto 库让 AES 算法在我正在做的一个小项目中工作。这就是我获得加密函数的方式:
var cipher:ICipher = Crypto.getCipher("simple-aes-cbc", key, Crypto.getPad("pkcs5"));
如您所见,我尝试将 AES-128 与 CBC 和 pkcs5 填充一起使用。
如果我的源数据长 128 字节,则加密数据为 160 字节。有人可以告诉我为什么会出现这个问题吗?
以下是我根据示例程序编译的一个小表。
源字符串长度 |加密字符串长度
15 | 15 32
16 | 16 48
31 | 48
32 | 32 64
事情应该是这样吗,还是我搞错了?
I am using the as3crypto library to get the AES algorithm working on a small project that i am doing. This is how i get the crypto function :
var cipher:ICipher = Crypto.getCipher("simple-aes-cbc", key, Crypto.getPad("pkcs5"));
As you can see, I am trying to use AES-128 with CBC and the pkcs5 padding.
If my source data is 128bytes long, the encrypted data is coming as 160bytes. Can some one tell me why this problem is coming?
Following is a small table that I compiled from a sample program.
Source string length | Encrypted string length
15 | 32
16 | 48
31 | 48
32 | 64
Is it supposed to be like this or have I made some mistake.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是这样的。您要求 PKCS5 填充 它总是添加至少一个字节的填充。当然,输入必须四舍五入为一定数量的整块,因为 AES 会生成 16 字节的输出块。使用半个块,您根本无法解密任何输入。
It is supposed to be like that. You asked for PKCS5 padding which always adds at least one byte of padding. And, of course, the input must be rounded up to some number of whole blocks because AES produces 16-byte chunks of output. With half a block, you cannot decrypt any of the input at all.