Menu
Choose a product
Viewing: v1.7.x (latest)
Find another version
Scroll for more
Open source
exportKey
The exportKey() method takes a
CryptoKey object as input and exports it in an external, portable format.
Note that for a key to be exportable, it must have been created with the extractable flag set to true.
Usage
exportKey(format, key)Parameters
Supported algorithms
| AES-CBC | AES-CTR | AES-GCM | AES-KW | ECDH | ECDSA | HMAC | PBKDF2 | RSA-OAEP | RSASSA-PKCS1-v1_5 | RSA-PSS |
|---|---|---|---|---|---|---|---|---|---|---|
| ✅ AesCbcParams | ✅ AesCtrParams | ✅ AesGcmParams | ❌ | ✅ EcdhKeyDeriveParams | ✅ EcdsaParams | ✅ HmacKeyGenParams | ✅ Pbkdf2Params | ✅ RsaHashedImportParams | ✅ RsaHashedImportParams | ✅ RsaHashedImportParams |
Supported formats
ECDHandECDSAalgorithms have support forpkcs8,spki,rawandjwkformats.RSA-OAEP,RSASSA-PKCS1-v1_5andRSA-PSSalgorithms have support forpkcs8,spkiandjwkformats.AES-*andHMACalgorithms have currently support forrawandjwkformats.PBKDF2algorithm has support forrawformat only.
Return Value
A Promise that resolves to a new ArrayBuffer or an
JsonWebKey object/dictionary containing the key.
Throws
| Type | Description |
|---|---|
InvalidAccessError | Raised when trying to export a non-extractable key. |
NotSupportedError | Raised when trying to export in an unknown format. |
TypeError | Raised when trying to use an invalid format. |
Example
JavaScript
JavaScript
export default async function () {
/**
* Generate a symmetric key using the AES-CBC algorithm.
*/
const generatedKey = await crypto.subtle.generateKey(
{
name: 'AES-CBC',
length: '256',
},
true,
['encrypt', 'decrypt']
);
/**
* Export the key in raw format.
*/
const exportedKey = await crypto.subtle.exportKey('raw', generatedKey);
/**
* Reimport the key in raw format to verify its integrity.
*/
const importedKey = await crypto.subtle.importKey('raw', exportedKey, 'AES-CBC', true, [
'encrypt',
'decrypt',
]);
console.log(JSON.stringify(importedKey));
}Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.