importSpkiKey static method

Future<RsaPssPublicKey> importSpkiKey(
  1. List<int> keyData,
  2. Hash hash
)

Import RSASSA-PSS public key in SPKI format.

Creates an RsaPssPublicKey from keyData given as the DER encoding of the SubjectPublicKeyInfo structure specified in RFC 5280. The hash algorithm to be used is specified by hash.

Throws FormatException if keyData is invalid.

Example

import 'package:webcrypto/webcrypto.dart';
import 'package:pem/pem.dart';

// Read key data from PEM encoded block. This will remove the
// '----BEGIN...' padding, decode base64 and return encoded bytes.
List<int> keyData = PemCodec(PemLabel.publicKey).decode("""
  -----BEGIN PUBLIC KEY-----
  MIGEAgEAMBAGByqG...
  -----END PUBLIC KEY-----
""");

// Import public key from binary PEM decoded data.
final publicKey = await RsaPssPublicKey.importSpkiKey(
  keyData,
  Hash.sha256,
);

// Export the key again (print it in same format as it was given).
List<int> rawKeyData = await publicKey.exportSpkiKey();
print(PemCodec(PemLabel.publicKey).encode(rawKeyData));

Implementation

static Future<RsaPssPublicKey> importSpkiKey(
  List<int> keyData,
  Hash hash,
) {
  return impl.rsaPssPublicKey_importSpkiKey(keyData, hash);
}