Exception in AES decryption algorithm in java

后端 未结 3 1386
太阳男子
太阳男子 2020-12-08 06:03

I got an exception in the following code for AES algorithm in java.

Code decryptes an encrypted string and returns the original string.

Plz help me to fix t

3条回答
  •  星月不相逢
    2020-12-08 06:38

    Your code manages to get almost everything wrong. Just for a start, your mistakes include:

    1. generating a new random symmetric key before encryption and decryption. You have to use the same key to decrypt that was used to encrypt.
    2. Using String as a container for binary data. cipher output is cannot be reliably made into a String unless you use an encoding, such as base64.
    3. Your exception handling is incorrect.

    Furthermore, your code runs without exceptions for me.

提交回复
热议问题