No results for

Powered byAlgolia


The importKey() imports a key from an external, portable format, and gives you a CryptoKey object that can be used with the Web Crypto API.


importKey(format, keyData, algorithm, extractable, keyUsages)


formatstringDefines the data format of the key to import. Currently supported formats: raw.
keyDataArrayBuffer, TypedArray or DataViewthe data to import the key from.
algorithma string or object with a single name string propertyThe algorithm to use to import the key. Currently supported algorithms: AES-CBC, AES-GCM, AES-CTR, and HMAC.
extractablebooleanIndicates whether it will be possible to export the key using exportKey.
keyUsagesArray<string>An array of strings describing what operations can be performed with the key. Currently supported usages include encrypt, decrypt, sign, and verify.

Return Value

A Promise that resolves with the imported key as a CryptoKey object.


SyntaxErrorRaised when the keyUsages parameter is empty but the key is of type secret or private.
TypeErrorRaised when trying to use an invalid format, or if the keyData is not suited for that format.


import { crypto } from "k6/experimental/webcrypto";
export default async function () {
* Generate a symmetric key using the AES-CBC algorithm.
const generatedKey = await crypto.subtle.generateKey(
name: "AES-CBC",
length: "256"
* Export the key in raw format.
const exportedKey = await crypto.subtle.exportKey("raw", generatedKey);
* Reimport the key in raw format to verfiy its integrity.
const importedKey = await crypto.subtle.importKey(
true, ["encrypt", "decrypt"]