我使用以下代码加密和解密,而解密我在运行时遇到错误。错误消息是“非法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);
秘密密钥:
private Key generateKey() {
Key secretKey = new SecretKeySpec(keyValue, ALGO);
return secretKey;
}
解密代码:
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);
String decryptedValue = decValue.toString();
如何在没有错误的情况下解密加密值
加密值= 3aW0qv4pN + y3Tj8raXDHtos95ChpLu2JzEnfW + KfgEE =
此值在弹簧控制器中显示为= 3aW0qv4pN y3Tj8raXDHtos95ChpLu2JzEnfW KfgEE =
它显示两个空格“+”转换为“(空格)”
现在我将我的密钥更改为'sa278asabmnbmnbm'
我的加密值为40SRNEe9PgaxEeprPyqlyeP08hBHq00Ow9WWBgP6ZTM =
解密时我得到[B @ 75141845作为解密值
预期:shamith@alraislabs.in