@@ -287,6 +287,57 @@ abstract class EcdhPublicKey {
287
287
return impl.ecdhPublicKey_importSpkiKey (keyData, curve);
288
288
}
289
289
290
+ /// Import ECDH public key in [JSON Web Key][1] format.
291
+ ///
292
+ /// {@macro importJsonWebKey:jwk}
293
+ ///
294
+ /// JSON Web Keys imported using [EcdhPublicKey.importJsonWebKey] must
295
+ /// have the following parameters:
296
+ /// * `"kty"` : The key type must be `"EC"` .
297
+ /// * `"crv"` : The curve used with the key. This MUST match the curve
298
+ /// parameter.
299
+ /// * `"x"` : The x coordinate for the Elliptic Curve point represented
300
+ /// as a [base64Url] encoded string. The length of this octet string MUST
301
+ /// be the full size of a coordinate for the curve specified in the `"crv"`
302
+ /// parameter.
303
+ /// * `"y"` : The y coordinate for the Elliptic Curve point represented
304
+ /// as a [base64url] encoded string. The length of this octet string MUST
305
+ /// be the full size of a coordinate for the curve specified in the `"crv"`
306
+ /// parameter.
307
+ ///
308
+ /// For importing a JWK with:
309
+ /// * `"crv": "P-256"` , use [EllipticCurve.p256] ,
310
+ /// * `"crv": "P-384"` , use [EllipticCurve.p384] , and,
311
+ /// * `"crv": "P-521"` , use [EllipticCurve.p521] .
312
+ ///
313
+ /// **Example**
314
+ /// ```dart
315
+ /// import 'dart:convert';
316
+ /// import 'package:webcrypto/webcrypto.dart';
317
+ ///
318
+ /// // JSON Web Key as map representing the decoded JSON.
319
+ /// final jwk = {
320
+ /// 'kty': 'EC',
321
+ /// 'crv': 'P-256',
322
+ /// 'x': 'kgR_PqO07L8sZOBbw6rvv7O_f7clqDeiE3WnMkb5EoI',
323
+ /// 'y': 'djI-XqCqSyO9GFk_QT_stROMCAROIvU8KOORBgQUemE'
324
+ /// };
325
+ ///
326
+ /// Future<void> main() async{
327
+ /// // Import public key from decoded JSON.
328
+ /// final jsonWebKey = await EcdhPublicKey.importJsonWebKey(
329
+ /// jwk,
330
+ /// EllipticCurve.p256,
331
+ /// );
332
+ ///
333
+ /// // Export the key (print it in same format as it was given).
334
+ /// final exportedJsonWebKey = await jsonWebKey.exportJsonWebKey();
335
+ ///
336
+ /// print(jsonEncode(exportedJsonWebKey));
337
+ /// }
338
+ /// ```
339
+ ///
340
+ /// [1] : https://www.rfc-editor.org/rfc/rfc7518.html#section-6.2
290
341
static Future <EcdhPublicKey > importJsonWebKey (
291
342
Map <String , dynamic > jwk,
292
343
EllipticCurve curve,
0 commit comments