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(Hmac(sha256, keys.hmacKey).convert(cipher).bytes)
      .replaceAll(RegExp(r'=+$'), '');
  if (hmac != data.mac.replaceAll(RegExp(r'=+$'), '')) {
    throw Exception('Bad MAC');
  }
  final decipher = await uc.aesCtr
      .encrypt(cipher, keys.aesKey, base64decodeUnpadded(data.iv));
  return String.fromCharCodes(decipher);
}