Skip to content

Commit

Permalink
docs: add example section for HmacSecretKey class (#103)
Browse files Browse the repository at this point in the history
* docs: add example section for HmacSecretKey class

* docs: remove exportRawKey and sign-verifyStream
  • Loading branch information
HamdaanAliQuatil authored May 6, 2024
1 parent a8fc471 commit 232f5d6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/src/webcrypto/webcrypto.hmac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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 {
Expand Down

0 comments on commit 232f5d6

Please sign in to comment.