importJsonWebKey static method

Future<RsaPssPrivateKey> importJsonWebKey(
  1. Map<String, dynamic> jwk,
  2. Hash hash
)

Import RSASSA-PSS private key in JSON Web Key format.

The jwk should be given as Map, String, List the same way jsonDecode from dart:convert represents decoded JSON values. The hash algorithm to be used is specified by hash.

JSON Web Keys imported using RsaPssPrivateKey.importJsonWebKey must have "kty": "RSA", and the hash given must match the hash algorithm implied by the "alg" property of the imported jwk.

For importing a JWK with:

Throws FormatException if jwk is invalid.

Example

import 'package:webcrypto/webcrypto.dart';
import 'dart:convert' show jsonEncode, jsonDecode;

// JSON Web Key as a string containing JSON.
final jwk = '{"kty": "RSA", "alg": "PS256", ...}';

// Import private key from decoded JSON.
final privateKey = await RsaPssPrivateKey.importJsonWebKey(
  jsonDecode(jwk),
  Hash.sha256, // Must match the hash used the JWK key "alg"
);

// Export the key (print it in same format as it was given).
Map<String, dynamic> keyData = await privateKey.exportJsonWebKey();
print(jsonEncode(keyData));

Warning, the "use" and "key_ops" properties from the jwk, specifying intended usage for public keys and allowed key operations, are ignored. If these properties are present they will have no effect. This is also the case when running on the web, as they will be stripped before the JWK is passed to the browser.

Implementation

static Future<RsaPssPrivateKey> importJsonWebKey(
  Map<String, dynamic> jwk,
  Hash hash,
) {
  return impl.rsaPssPrivateKey_importJsonWebKey(jwk, hash);
}