且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#AES:加密文件的原因"数据长度加密无效"。错误

更新时间:2023-02-17 17:27:45

一个分组密码输入期望用长度是块大小的倍数。随着AES,输入的长度必须是16的倍数。

A block cipher expects input with a length that is a multiple of the block size. With AES, the length of the input must be a multiple of 16.

您必须向明文某种填充,使这一要求得到满足。 PKCS#7填充是***的选择。

You must apply some sort of padding to the plaintext so that this requirement is satisfied. PKCS#7 padding is the best choice.

不过,经过再三考虑,CFB模式将块加密成一个流密码。流密码不需要填充。的.NET实现似乎在这方面被打破。

However, on second thought, CFB mode turns a block cipher into a stream cipher. Stream ciphers don't need padding. The .NET implementation seems to be broken in this regard.