flutter 用 encrypt: ^5.0.1例子即可 key iv 可以用自定义字符串:IV _ivAes = IV.fromUtf8(“1234456812344568”);
java 对应的key与iv也要用同样的字符串: String key = “12344568123445681234456812344568” String iv = “1234456812344568”; 没加密过的字符串转化为byte[]: // key byte[] keyByte = key.getBytes(StandardCharsets.UTF_8); // iv byte[] ivByte = iv.getBytes(StandardCharsets.UTF_8); 加密过的字符串则要同时解密后再用: byte[] keyByte = Base64.decodeBase64(key); byte[] ivByte = Base64.decodeBase64(iv.getBytes(StandardCharsets.UTF_8));
java javax.crypto.BadPaddingException: pad block corrupted问题解决 我用的是Java\jdk-12.0.1,security下没有两个jar包。试了如下办法,成功解密
Cipher的填空("AES/OFB/PKCS7Padding", "BC");只中间有OFB和CFB有用,第三个不能用NoPadding
//Cipher cipher = Cipher.getInstance("AES/OFB/PKCS5Padding", "BC");//成功了
//Cipher cipher = Cipher.getInstance("AES/CFB/ISO10126Padding", "BC");//成功了
//Cipher cipher = Cipher.getInstance("AES/CFB/PKCS5Padding", "BC");//成功了
//Cipher cipher = Cipher.getInstance("AES/OFB/ISO10126Padding", "BC");//成功了
Cipher cipher = Cipher.getInstance("AES/OFB/PKCS7Padding", "BC");//成功
//Cipher cipher = Cipher.getInstance("AES/CFB/ISO10126Padding", "BC");//成功了
|