File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,28 @@ part of 'webcrypto.dart';
25
25
/// * [JWK] format using [HmacSecretKey.importJsonWebKey] .
26
26
///
27
27
/// 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
+ ///
29
50
/// [1] : https://doi.org/10.6028/NIST.FIPS.180-4
30
51
@sealed
31
52
abstract class HmacSecretKey {
You can’t perform that action at this time.
0 commit comments