importJsonWebKey static method

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

Import RSASSA-PSS public 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 RsaPssPublicKey.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 public key from decoded JSON.
final publicKey = await RsaPssPublicKey.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 publicKey.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<RsaPssPublicKey> importJsonWebKey(
  Map<String, dynamic> jwk,
  Hash hash,
) {
  return impl.rsaPssPublicKey_importJsonWebKey(jwk, hash);
}