exportKey method

Exports the given key material of the Key object as specified by the key parameter.

Important  As of Microsoft Edge, this method returns a Promise object. See Web Cryptography API updates for more info.



var retVal = SubtleCrypto.exportKey(format, key);


format [in]

Type: DOMString

A DOM string specifying the format of the exported key material, such as raw, pkcs8, spki, or jwk. For details, see the below remarks section.

key [in]

Type: Key

The key to export.

Return value

Type: Promise

A Promise object that will return the exported key material.

Note  IE11 returns a KeyOperation. See Web Cryptography API updates for more info.


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.
Note  This method exports the key material in unencrypted form (in the clear). Exported key material must be handled in accordance with good security practices.

See also