小编Sha*_*mar的帖子

控制台错误“非法的base64字符20”

我使用以下代码进行加密和解密,而解密时我在运行时收到错误。错误消息是“非法的 base64 字符 20”

加密代码:

String secretValue = "sazhwsxplokmeroo";
keyValue = secretValue.getBytes();
Key generatedKey = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, generatedKey);
byte[] encValue = c.doFinal(userEmail.getBytes());
String encryptedValue = Base64.getEncoder().encodeToString(encValue);
Run Code Online (Sandbox Code Playgroud)

密钥:

 private Key generateKey() {
     Key secretKey = new SecretKeySpec(keyValue, ALGO);
     return secretKey;
}
Run Code Online (Sandbox Code Playgroud)

解密代码:

String secretValue = "sazhwsxplokmeroo";
keyValue = secretValue.getBytes();
Key generatedKey = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.DECRYPT_MODE, generatedKey);
byte[] decodedValue = Base64.getDecoder().decode(encryptEmail.getBytes()); //error throws from this line as illegal base64 character 20
byte[] decValue = c.doFinal(decodedValue); …
Run Code Online (Sandbox Code Playgroud)

java base64 aes

5
推荐指数
0
解决办法
2万
查看次数

标签 统计

aes ×1

base64 ×1

java ×1