Constructs a new Key object using the key data specified by the keyData parameter.
Syntaxvar retVal = SubtleCrypto.importKey(format, keyData, algorithm, extractable, keyUsages);
- format [in]
A DOM string specifying the format of keyData's key material, such as raw, pkcs8, spki, or jwk. For details, see the below remarks section.
- keyData [in]
The key data to import.
- algorithm [in]
An object identifying the cryptographic algorithm for use with the output Key object (along with any required parameters). If these conflict with the algorithm parameters contained in keyData, the parameters in keyData take precedence.
- extractable [in, optional]
Whether or not keying material may be exported from the Key object created by this operation. The default value is false.
- keyUsages [in, optional]
An array containing one or more of the following DOM strings: encrypt, decrypt, sign, verify, derive, wrap, unwrap. These are the operations that the Key object created by this operation will be permitted to perform.
With respect to supported cryptographic algorithms, any key which can be generated can be imported and exported.
The supported formats for both importKey and exportKey are as follows:
- raw - An unformatted sequence of bytes. Intended for secret keys.
- pkcs8 - The DER encoding of the PrivateKeyInfo structure from RFC 5208.
- spki - The DER encoding of the SubjectPublicKeyInfo structure from RFC 5280.
- jwk - The key is represented as JSON according to the JSON Web Key format.
For a code example, see exportKey.