Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example section for HmacSecretKey class #103

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading