有人可以告诉我为什么会收到此错误消息吗?显然这是我缺少的某种转换
预期 IV 长度为 16,但为 24
要调用它,我使用
String encrypted = "E5ADDEB05D9D7B3925B7DE16B560D87C";
String sKey = "3985661DD71D591665BD39476636486B";
String sIv = "75E5FBB56AA78D05D246078A782553E1";
String decrypted = decrypt2(encrypted, sKey, sIv);
Log.i("--------------------------------> ", decrypted);
这是程序
public static String decrypt2(final String EncryptedMessageBase64,
final String symKeyHex,
final String sIvHex) {
final byte[] symKeyData = Base64.decode((symKeyHex),Base64.DEFAULT);
final byte[] byIvData = Base64.decode((sIvHex), Base64.DEFAULT);
final byte[] EncryptedMessage = Base64.decode(EncryptedMessageBase64, Base64.DEFAULT);
try
{
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
final int blockSize = cipher.getBlockSize();
final SecretKeySpec symKey = new SecretKeySpec(symKeyData, "AES");
Log.i("### iv size -------->", String.valueOf(blockSize));
Log.i("### symKeyHex -------->", symKeyHex);
Log.i("### sIvHex -------->", sIvHex);
Log.i("### blockSize -------->", String.valueOf(blockSize));
final IvParameterSpec iv = new IvParameterSpec(byIvData);
final byte[] encryptedMessage = new byte[EncryptedMessage.length];
cipher.init(Cipher.DECRYPT_MODE, symKey, iv);
这是输出
### iv size -------->: 16
### symKeyHex -------->: 3985661DD71D591665BD39476636486B
### sIvHex -------->: 75E5FBB56AA78D05D246078A782553E1
### blockSize -------->: 16
error: expected IV length of 16 but was 24