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

Document exportPkcs8Key in the EcdhPrivateKey Class #131

Merged
merged 3 commits into from
Jun 4, 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: 23 additions & 0 deletions lib/src/webcrypto/webcrypto.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,29 @@ abstract class EcdhPrivateKey {
// https://tools.ietf.org/html/rfc6090#appendix-B
Future<Uint8List> deriveBits(int length, EcdhPublicKey publicKey);

/// Export the [EcdhPrivateKey] as a [PKCS #8][1] key.
///
/// Returns the DER encoding of the _PrivateKeyInfo_ structure specified in [RFC 5208][1] as a list of bytes.
///
/// **Example**
/// ```dart
/// import 'package:pem/pem.dart';
/// import 'package:webcrypto/webcrypto.dart';
///
/// Future<void> main() async {
/// // Generate a key-pair
/// final kp = await EcdhPrivateKey.generateKey(EllipticCurve.p256);
///
/// // Export the private key.
/// final exportedPkcs8Key = await kp.privateKey.exportPkcs8Key();
///
/// // Private keys are often encoded as PEM.
/// // This encodes the key in base64 and wraps it with:
/// // '-----BEGIN PRIVATE KEY----'...
/// print(PemCodec(PemLabel.privateKey).encode(exportedPkcs8Key));
/// }
/// ```
/// [1]: https://datatracker.ietf.org/doc/html/rfc5208
Future<Uint8List> exportPkcs8Key();

Future<Map<String, dynamic>> exportJsonWebKey();
Expand Down
Loading