Bad PKCS7 Padding error: Invalid length 106

感情迁移 提交于 2019-12-01 13:23:26

You don't appear to be setting the IV when encrypting, and so a random IV will be used automatically. Since you are setting the IV when decrypting (and it won't be the same as was used during encryption), the first output block will be corrupt. If the message is short enough (< 1 block), then the padding will also be corrupt likely resulting in this error.

As usual, I'll note that among other possible issues, the use of the same IV as key is bad practice, as is the use of Encoding.UTF8.GetBytes() for key derivation.

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