AESManaged Encryption/Decryption - Padding is invalid and cannot be removed

谁说胖子不能爱 提交于 2019-12-05 19:48:45

Your key is 56 bytes long when it gets to the encrypt method that due to the encoding, but you can't have this if your using AesManaged, AesManaged will only accept 16 byte (128 bit) key and same for the IV.

If you want to use 256 bit key encryption then you need to switch to RijndaelManaged. Aes specification does not support variable key lengths. It only uses fixed key lengths (128, 192 or 256 bits).

If you need variable key lengths then you may need to look at RC2 that supports key lengths for anything between 8–128 bits.

Hope this helps.

If you want to use 256 bit key encryption then you need to switch to RijndaelManaged. Aes specification does not support variable key lengths. It only uses fixed key lengths (128, 192 or 256 bits).

As far as i know AES supports only a fixed blocksize of 128 bit but u can still use a 256 bit key. So if youre fine with a blocksize of 128 bit you can still stick with the aesmanaged class.

correct me if im wrong.

You assume that

Encoding.ASCII.GetBytes(Encoding.ASCII.GetString(x))==x

but that is not true for an arbitrary bytearray.

If you really need to encode the bytearray as a string, you should use Base-64.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!