decryptAes static method

Future<String> decryptAes(
  1. EncryptedContent data,
  2. Uint8List key,
  3. String name
)

Implementation

static Future<String> decryptAes(
  EncryptedContent data,
  Uint8List key,
  String name,
) async {
  final keys = deriveKeys(key, name);
  final cipher = base64decodeUnpadded(data.ciphertext);
  final hmac = base64
      .encode(CryptoUtils.hmac(key: keys.hmacKey, input: cipher))
      .replaceAll(RegExp(r'=+$'), '');
  if (hmac != data.mac.replaceAll(RegExp(r'=+$'), '')) {
    throw Exception('Bad MAC');
  }
  final decipher = CryptoUtils.aesCtr(
    input: cipher,
    key: keys.aesKey,
    iv: base64decodeUnpadded(data.iv),
  );
  return String.fromCharCodes(decipher);
}