importSpkiKey static method

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

Import RSAES-OAEP public key in SPKI format.

Creates an RsaOaepPublicKey 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 RsaOaepPublicKey.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<RsaOaepPublicKey> importSpkiKey(
  List<int> keyData,
  Hash hash,
) {
  return impl.rsaOaepPublicKey_importSpkiKey(keyData, hash);
}