aesCbcDecrypt method

Uint8List aesCbcDecrypt(
  1. Uint8List key,
  2. Uint8List cipherText
)

Implementation

Uint8List aesCbcDecrypt(Uint8List key, Uint8List cipherText) {
  assert([128, 192, 256].contains(key.length * 8));

  // final cbc = CBCBlockCipher(AESEngine())
  //   ..init(false,
  //       ParametersWithIV(KeyParameter(key), Uint8List(16))); // false=decrypt

  // return cbc.process(cipherText);

  final CBCBlockCipher cbcCipher = CBCBlockCipher(AESEngine());
  final ParametersWithIV<KeyParameter> ivParams =
      ParametersWithIV<KeyParameter>(KeyParameter(key), Uint8List(16));
  final PaddedBlockCipherParameters<ParametersWithIV<KeyParameter>, Null>
      paddingParams =
      PaddedBlockCipherParameters<ParametersWithIV<KeyParameter>, Null>(
          ivParams, null);
  final PaddedBlockCipherImpl paddedCipher =
      PaddedBlockCipherImpl(PKCS7Padding(), cbcCipher);
  paddedCipher.init(false, paddingParams);
  final decrypted = paddedCipher.process(cipherText);
  return decrypted;
}