importPkcs8Key static method
Import RSASSA-PSS private key in PKCS #8 format.
Creates an RsaPssPrivateKey
from keyData
given as the DER
encoding of the PrivateKeyInfo structure specified in RFC 5208.
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.privateKey).decode("""
-----BEGIN PRIVATE KEY-----
MIGEAgEAMBAGByqG...
-----END PRIVATE KEY-----
""");
// Import private key from binary PEM decoded data.
final privateKey = await RsaPssPrivateKey.importPkcs8Key(
keyData,
Hash.sha256,
);
// Export the key again (print it in same format as it was given).
List<int> rawKeyData = await privateKey.exportPkcs8Key();
print(PemCodec(PemLabel.privateKey).encode(rawKeyData));
Implementation
static Future<RsaPssPrivateKey> importPkcs8Key(
List<int> keyData,
Hash hash,
) {
return impl.rsaPssPrivateKey_importPkcs8Key(keyData, hash);
}