Skip to content

Commit 56dc3db

Browse files
Document exportPkcs8Key in the EcdhPrivateKey Class (#131)
* docs: document exportPkcs8Ket in EcdhPrivateKey * Update lib/src/webcrypto/webcrypto.ecdh.dart Co-authored-by: Jonas Finnemann Jensen <[email protected]> * Update lib/src/webcrypto/webcrypto.ecdh.dart Co-authored-by: Jonas Finnemann Jensen <[email protected]> --------- Co-authored-by: Jonas Finnemann Jensen <[email protected]>
1 parent a0c8e43 commit 56dc3db

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/src/webcrypto/webcrypto.ecdh.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,29 @@ abstract class EcdhPrivateKey {
204204
// https://tools.ietf.org/html/rfc6090#appendix-B
205205
Future<Uint8List> deriveBits(int length, EcdhPublicKey publicKey);
206206

207+
/// Export the [EcdhPrivateKey] as a [PKCS #8][1] key.
208+
///
209+
/// Returns the DER encoding of the _PrivateKeyInfo_ structure specified in [RFC 5208][1] as a list of bytes.
210+
///
211+
/// **Example**
212+
/// ```dart
213+
/// import 'package:pem/pem.dart';
214+
/// import 'package:webcrypto/webcrypto.dart';
215+
///
216+
/// Future<void> main() async {
217+
/// // Generate a key-pair
218+
/// final kp = await EcdhPrivateKey.generateKey(EllipticCurve.p256);
219+
///
220+
/// // Export the private key.
221+
/// final exportedPkcs8Key = await kp.privateKey.exportPkcs8Key();
222+
///
223+
/// // Private keys are often encoded as PEM.
224+
/// // This encodes the key in base64 and wraps it with:
225+
/// // '-----BEGIN PRIVATE KEY----'...
226+
/// print(PemCodec(PemLabel.privateKey).encode(exportedPkcs8Key));
227+
/// }
228+
/// ```
229+
/// [1]: https://datatracker.ietf.org/doc/html/rfc5208
207230
Future<Uint8List> exportPkcs8Key();
208231

209232
/// Export the [EcdhPrivateKey] as a [JSON Web Key][1].

0 commit comments

Comments
 (0)