Skip to content

Commit

Permalink
Document importPkcs8Key in the EcdhPrivateKey Class (#121)
Browse files Browse the repository at this point in the history
* docs: document importPkcs8Key in EcdhPrivateKey

* docs: add review edit

* Update lib/src/webcrypto/webcrypto.ecdh.dart

---------

Co-authored-by: Jonas Finnemann Jensen <[email protected]>
  • Loading branch information
HamdaanAliQuatil and jonasfj authored May 30, 2024
1 parent 2b1d99e commit c6393ba
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/src/webcrypto/webcrypto.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@ part of 'webcrypto.dart';
abstract class EcdhPrivateKey {
EcdhPrivateKey._(); // keep the constructor private.

/// Import [EcdhPrivateKey] in the [PKCS #8][1] format.
///
/// Creates an [EcdhPrivateKey] from [keyData] given as the DER encodeding _PrivateKeyInfo structure_ specified in [RFC 5208][1].
/// The [curve] specified must match the curved used in [keyData].
///
/// **Example**
/// ```dart
/// import 'package:pem/pem.dart';
/// import 'package:webcrypto/webcrypto.dart';
///
/// // Read key data from a PEM encoded block. This will remove the
/// // the padding, decode base64 and return the encoded bytes.
/// List<int> keyData = PemCodec(PemLabel.privateKey).decode('''
/// -----BEGIN PRIVATE KEY-----
/// MIGHAgEAMBMGByqGSM4.....
/// -----END PRIVATE KEY-----
/// ''');
///
///
/// Future<void> main() async {
/// // Import the Private Key from a Binary PEM decoded data.
/// final privateKey = await EcdhPrivateKey.importPkcs8Key(
/// keyData,
/// EllipticCurve.p256,
/// );
///
/// // Export the private key (print it in same format as it was given).
/// final exportedPkcs8Key = await privateKey.exportPkcs8Key();
/// print(PemCodec(PemLabel.privateKey).encode(exportedPkcs8Key));
/// }
/// ```
///
/// [1]: https://datatracker.ietf.org/doc/html/rfc5208
static Future<EcdhPrivateKey> importPkcs8Key(
List<int> keyData,
EllipticCurve curve,
Expand Down

0 comments on commit c6393ba

Please sign in to comment.