Skip to content

Commit 232f5d6

Browse files
docs: add example section for HmacSecretKey class (#103)
* docs: add example section for HmacSecretKey class * docs: remove exportRawKey and sign-verifyStream
1 parent a8fc471 commit 232f5d6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/src/webcrypto/webcrypto.hmac.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,28 @@ part of 'webcrypto.dart';
2525
/// * [JWK] format using [HmacSecretKey.importJsonWebKey].
2626
///
2727
/// A random key can also be generated using [HmacSecretKey.generateKey].
28-
///
28+
///
29+
/// **Example**
30+
/// ```dart
31+
/// import 'package:webcrypto/webcrypto.dart';
32+
/// import 'dart:convert';
33+
///
34+
/// Future<void> main() async {
35+
/// // Generate an HMAC secret key using SHA-256 hash algorithm.
36+
/// final key = await HmacSecretKey.generateKey(Hash.sha256);
37+
///
38+
/// // Sign the message.
39+
/// final signature = await key.signBytes(utf8.encode('Hello World!'));
40+
///
41+
/// // Verify the signature.
42+
/// final verified = await key.verifyBytes(signature, utf8.encode('Hello World!'));
43+
/// assert(verified == true, 'Signature should be valid');
44+
///
45+
/// // Export the key as a JSON Web Key.
46+
/// final jwk = await key.exportJsonWebKey();
47+
/// }
48+
/// ```
49+
///
2950
/// [1]: https://doi.org/10.6028/NIST.FIPS.180-4
3051
@sealed
3152
abstract class HmacSecretKey {

0 commit comments

Comments
 (0)