当我解密消息时,有一定数量的字符未正确解密。例如:
在解密前:{"标题":{" messageId":" ca18d015-9861-47b8-9e09-81fb561522e5"
解密后:M��s����g�{�T\ ageId":" ca18d015-9861-47b8-9e09-81fb561522e5"
我正在使用以下代码初始化JCE:
SecretKeyFactory factory = SecretKeyFactory
.getInstance(KEY_DERIVATION_ALGORITHM);
SecretKey tmp = factory.generateSecret(new PBEKeySpec(new String(dataKey).toCharArray(), SALT,
PBKDF_DEFAULT_ITERATIONS, 128));
Key aesKey = new SecretKeySpec(tmp.getEncoded(), KEY_TYPE);
Cipher cipher = Cipher.getInstance(CIPHER);
cipher.init(Cipher.ENCRYPT_MODE, aesKey, new IvParameterSpec(initializationVector));
byte[] encrypted = cipher.doFinal(payload.getBytes());
答案 0 :(得分:0)
初始化向量在加密/解密时有所不同。