signBytes abstract method
Compute an HMAC signature of given data
.
This computes an HMAC signature of the data
using hash algorithm
and secret key material held by this HmacSecretKey.
Example
import 'dart:convert' show base64, utf8;
import 'package:webcrypto/webcrypto.dart';
// Generate an HmacSecretKey.
final key = await HmacSecretKey.generateKey(Hash.sha256);
String stringToSign = 'example-string-to-signed';
// Compute signature.
final signature = await key.signBytes(utf8.encode(stringToSign));
// Print as base64
print(base64.encode(signature));
This method should not be used for validating other signatures by generating a new signature and then comparing the two signatures. While this technically works, your application might be vulnerable to timing attacks. To validate signatures use verifyBytes or verifyStream instead, these methods computes a signature and does a fixed-time comparison.
Implementation
Future<Uint8List> signBytes(List<int> data);