【发布时间】:2012-07-02 11:06:28
【问题描述】:
我将一个 XML 文件作为字节数组导入到项目中
RandomAccessFile rnd = new RandomAccessFile(filePath, "r");
byte[] fileData = new byte[(int) rnd.length()];
rnd.read(fileData);
我使用 java.crypto 加密了数组
Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
byte[] encypted = new byte[cipher.getOutputSize(fileData.length)];
int len = cipher.update(fileData, 0, fileData.length, encypted, 0);
len += cipher.doFinal(encypted, len);
当我解密字节数组并使用它打印时
System.out.println(new String(decrypted, "UTF-8"));
我得到了 XML 文件,但末尾有一些未知字符(它们仅在末尾)。有什么办法可以去掉吗?
提前致谢
【问题讨论】:
标签: java encryption