我使用以下代码进行加密和解密,而解密时我在运行时收到错误。错误消息是“非法的 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)