BadPaddingException: invalid ciphertext

亡梦爱人 提交于 2019-11-30 10:39:21

You cannot just use the cipher text as input for the String constructor, as you are doing in this line:

encryptedMessage = new String(encryptedData, "UTF-8");

You will have to use an encoding such as Base 64 as you did with the keys, if you want to communicate the cipher text using strings instead of bytes.

Encryption will result in data that looks like random bytes. Not all bytes have a character equivalent. The result of the conversion depends on the character encoding. UTF-8 may use many bytes, and many combinations won't result in correct characters. Java silently converts these, check the Charset and related classes for more information.

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