The SubtleCrypto.exportKey() method returns a Promise of the key encrypted in the requested format. If the key is not extractable, that is if CryptoKey.extractable returns false, the promise fails with an InvalidAccessError exception; it the format is unknown, the promise fails with a NotSupported exception.
var result = crypto.subtle.exportKey(format, key);
format is an enumerated value describing the data format in which the key has to be exported. It can be one of the following: "raw", the key as an array of bytes, usually a secret key."pkcs8" a private key, in the IETF Public Key-Cryptographic Standard Encryption #8."spki", the public key in DER encoding of the SubjectPublicKeyInfo structure from RFC 5280."jwk", the key in the JSON Web Key format.key is the CryptoKey to export.result is a Promise that returns the key in the requested format.The promise is rejected when one of the following exceptions is encountered:
InvalidAccessError when trying to export an non-extractable key.NotSupported when trying to export in an unknown format.TypeError when trying to use an invalid format.| Specification | Status | Comment |
|---|---|---|
| Web Cryptography API The definition of 'SubtleCrypto.exportKey()' in that specification. | Recommendation | Initial definition. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 37 | 12 | 34
|
11
|
24 | 7 |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | 37 | 37 | 12 | 34
|
24 | 7 | 6.0 |
Crypto and Crypto.subtle.SubtleCrypto, the interface it belongs to.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/exportKey