decrypt static method

Future<Uint8List> decrypt(
  1. Uint8List data,
  2. Uint8List key,
  3. Uint8List iv
)

Implementation

static Future<Uint8List> decrypt(Uint8List data, Uint8List key, Uint8List iv) async {
  try {
    final keyParameter = KeyParameter(key);
    final params = ParametersWithIV(keyParameter, iv);

    PaddedBlockCipherParameters<CipherParameters?, CipherParameters?> paddingParams =
        PaddedBlockCipherParameters<CipherParameters?, CipherParameters?>(params, null);

    // ignore: deprecated_member_use
    final cipher = PaddedBlockCipherImpl(PKCS7Padding(), CBCBlockCipher(AESFastEngine()));
    cipher.init(false, paddingParams);

    final decryptedData = cipher.process(Uint8List.fromList(data));

    return Uint8List.fromList(decryptedData);
  } catch (e) {
    throw DecryptionError.decryptionFailed;
  }
}