使用以下代码,我正在执行 AES 加密操作,我在不同的实例中传递相同的输入,但我得到不同的密码。为什么会这样?
public static byte[] encrypt(byte[] plainText, byte[] key)
{
byte[] passwordKey128 = Arrays.copyOfRange(key, 0, 16);
SecretKeySpec secretKey = new SecretKeySpec(passwordKey128, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] cipherText = cipher.doFinal(plainText);
return cipherText;
}
输入是
encrypt(new byte[]{-17, -60, -70, 24, 80, 35, 2, -62, -79, 19, -55, -50, -62, -69, -80, -96} ,new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} );
在一个实例中,密码是 - [0, 91, -96, 80, -44, -93, 107, 62, 4, -10, 103, 119, 109, 4, 25, 68]
在另一个实例中,密码是 - [87, 109, 20, 69, 18, 6, 103, 92, -57, 62, -41, -103, -18, -19, 74, 87]
可能是什么原因?