你需要有一个静脉注射是不可预测的一个给定的信息。硬编码的IV使它可以预测。所以你需要想出一些方法,用密文传递IV。与钥匙不同,静脉注射不需要保密。
分组密码对固定大小的明文块进行操作。如果您没有足够的纯文本输入,则必须对其进行填充,以便收件人能够区分填充和数据。链接的示例完全忽略了这一点,这是一个错误。如果
CipherOutputStream
Cipher
doFinal
SecretKey secret = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secret);
AlgorithmParameters param = cipher.getParameters();
/* In addition to ciphertext in "cos", recipient needs IV. */
byte[] iv = param.getParameterSpec(IvParameterSpec.class).getIV();
CipherOutputStream cos = new CipherOutputStream(output, cipher);
byte[] buf = new byte[2048];
while (true) {
int n = input.read(buf, 0, buf.length);
if (n < 0)
break;
cos.write(buf, 0, n);
}
cos.flush();
接收要加密的明文的JSP在哪里?您希望JSP如何格式化其输出(包括IV)?