verifyHmac method

  1. @override
Future<bool> verifyHmac({
  1. required EncryptedPayload payload,
  2. required Uint8List key,
})
override

Verify the hmac and returns true if valid.

Implementation

@override
Future<bool> verifyHmac({
  required EncryptedPayload payload,
  required Uint8List key,
}) async {
  final cipherText = Uint8List.fromList(hex.decode(payload.data));
  final iv = Uint8List.fromList(hex.decode(payload.iv));
  final unsigned = Uint8List.fromList([...cipherText, ...iv]);

  final hmacsha256 = Hmac.sha256();
  final secretKey = SecretKey(List<int>.unmodifiable(key));
  final chmac = await hmacsha256.calculateMac(unsigned, secretKey: secretKey);

  return hex.encode(chmac.bytes) == payload.hmac;
}