我想用AES加密和解密整数,但无法实现。
为了测试基本的加密过程,我写了一个简单的方法,它接受输入数据,用相同的参数加密和解密它并返回结果。
这是我失败的JUnit测试用例,它检查输入和输出数据是否相等。@Test
public void test4() throws UnsupportedEncodingException {
Random random = new Random();
SecretKey secretKey = Tools.generateKey("secretKey".getBytes("UTF-8"));
byte[] initializationVector = Tools.intToByteArray(random.nextInt());
// ensuring that the initialization vector has the correct length
byte[] ivHash = Tools.hashMD5(initializationVector);
int value = random.nextInt();
byte[] input = Tools.intToByteArray(value);
byte[] received = Tools.enDeCrypt(input, secretKey, ivHash);
assertEquals(data.hashCode(), received.hashCode());
}
方法generateKey:public static SecretKeySpec generateKey(byte[] secretKey) {
try