我发现一个观点认为最好对整个数据库进行加密,并且在加密期间可以看到一些元数据。我们在谈论什么元数据,我应该怎么做(我已经创建了一个加密每个条目的程序)
主页
/
user-399935
Serzh's questions
AES CBC 会截断长度超过 16 个字符的字符串。下次运行时,它显示 javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
UPD:这是有问题的代码:
public static byte[][] encrypt(String txt, String txt2, String txt3){
try {
SecretKey mysecretKey = new SecretKeySpec("qwertyuiopasdfgh".getBytes(), "AES");
byte[] plainText1 = txt.getBytes();
byte[] plainText2 = txt2.getBytes();
byte[] plainText3 = txt3.getBytes();
byte[][] plain_bytes = new byte[][] { plainText1, plainText2, plainText3 };
IvParameterSpec iv = new IvParameterSpec("4283810222669651".getBytes());
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, mysecretKey, iv);
cipher.update(plainText1);
byte[] cipherText1 = cipher.doFinal();
cipher.update(plainText2);
byte[] cipherText2 = cipher.doFinal();
cipher.update(plainText3);
byte[] cipherText3 = cipher.doFinal();
byte[][] encrypted_bytes = new byte[][] { cipherText1, cipherText2, cipherText3 };
String str = Base64.getEncoder().encodeToString(encrypted_bytes[0]);
encryptedUrl = str;
System.out.println(encryptedUrl);
return encrypted_bytes;
} catch (Exception e1) {
e1.printStackTrace();
return null;
}
}