diff --git a/lib/src/webcrypto/webcrypto.hmac.dart b/lib/src/webcrypto/webcrypto.hmac.dart index c4300072..04b046bd 100644 --- a/lib/src/webcrypto/webcrypto.hmac.dart +++ b/lib/src/webcrypto/webcrypto.hmac.dart @@ -25,7 +25,28 @@ part of 'webcrypto.dart'; /// * [JWK] format using [HmacSecretKey.importJsonWebKey]. /// /// A random key can also be generated using [HmacSecretKey.generateKey]. -/// +/// +/// **Example** +/// ```dart +/// import 'package:webcrypto/webcrypto.dart'; +/// import 'dart:convert'; +/// +/// Future main() async { +/// // Generate an HMAC secret key using SHA-256 hash algorithm. +/// final key = await HmacSecretKey.generateKey(Hash.sha256); +/// +/// // Sign the message. +/// final signature = await key.signBytes(utf8.encode('Hello World!')); +/// +/// // Verify the signature. +/// final verified = await key.verifyBytes(signature, utf8.encode('Hello World!')); +/// assert(verified == true, 'Signature should be valid'); +/// +/// // Export the key as a JSON Web Key. +/// final jwk = await key.exportJsonWebKey(); +/// } +/// ``` +/// /// [1]: https://doi.org/10.6028/NIST.FIPS.180-4 @sealed abstract class HmacSecretKey {