【发布时间】:2015-04-04 22:08:27
【问题描述】:
关于这个问题; Java (Android) Decrypting msg with IV attached
我的消息可以正常解密,但包含不需要的 IV 字节数据。
我尝试删除附加的 IV,但它并没有删除所有字符,并且某些字符总是留在后面。我不确定我应该如何计算编码 IV 的长度以删除不需要的字符。
public String decrypt(String cipherText, byte[] encryptionKey) throws Exception {
SecretKeySpec key = new SecretKeySpec(encryptionKey, "AES");
cipher.init(Cipher.DECRYPT_MODE, key, iV);
String decrypt = new String(cipher.doFinal( Base64.decode(cipherText, Base64.DEFAULT)));
byte[] decryptData = new byte[decrypt.getBytes().length - iV.getIV().length];
System.arraycopy(decrypt.getBytes(), iV.getIV().length, decryptData, 0, decrypt.getBytes().length - iV.getIV().length);
Log.d("decrypt = ", decrypt);
decrypt = new String(decryptData, "UTF-8");
return decrypt;
}
【问题讨论】:
标签: java android encryption base64 initialization-vector