Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/latest/javascript-api/crypto/subtlecrypto/exportkey.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/latest/javascript-api/crypto/subtlecrypto/exportkey/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
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
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

