@@ -18,6 +18,39 @@ part of 'webcrypto.dart';
18
18
abstract class EcdhPrivateKey {
19
19
EcdhPrivateKey ._(); // keep the constructor private.
20
20
21
+ /// Import [EcdhPrivateKey] in the [PKCS #8][1] format.
22
+ ///
23
+ /// Creates an [EcdhPrivateKey] from [keyData] given as the DER encodeding _PrivateKeyInfo structure_ specified in [RFC 5208][1] .
24
+ /// The [curve] specified must match the curved used in [keyData] .
25
+ ///
26
+ /// **Example**
27
+ /// ```dart
28
+ /// import 'package:pem/pem.dart';
29
+ /// import 'package:webcrypto/webcrypto.dart';
30
+ ///
31
+ /// // Read key data from a PEM encoded block. This will remove the
32
+ /// // the padding, decode base64 and return the encoded bytes.
33
+ /// List<int> keyData = PemCodec(PemLabel.privateKey).decode('''
34
+ /// -----BEGIN PRIVATE KEY-----
35
+ /// MIGHAgEAMBMGByqGSM4.....
36
+ /// -----END PRIVATE KEY-----
37
+ /// ''');
38
+ ///
39
+ ///
40
+ /// Future<void> main() async {
41
+ /// // Import the Private Key from a Binary PEM decoded data.
42
+ /// final privateKey = await EcdhPrivateKey.importPkcs8Key(
43
+ /// keyData,
44
+ /// EllipticCurve.p256,
45
+ /// );
46
+ ///
47
+ /// // Export the private key (print it in same format as it was given).
48
+ /// final exportedPkcs8Key = await privateKey.exportPkcs8Key();
49
+ /// print(PemCodec(PemLabel.privateKey).encode(exportedPkcs8Key));
50
+ /// }
51
+ /// ```
52
+ ///
53
+ /// [1] : https://datatracker.ietf.org/doc/html/rfc5208
21
54
static Future <EcdhPrivateKey > importPkcs8Key (
22
55
List <int > keyData,
23
56
EllipticCurve curve,
0 commit comments