generateKey
The generateKey()
generates a new cryptographic key and returns it as a CryptoKey object or a CryptoKeyPair object that can be used with the Web Crypto API.
Usage
generateKey(algorithm, extractable, keyUsages)
Parameters
Supported algorithms
Caution
The experimental module
k6/experimental/webcrypto
has graduated, and its functionality is now available globally through thecrypto
object. Thek6/experimental/webcrypto
is deprecated and will be removed in the near future.To migrate your scripts, remove the
k6/experimental/webcrypto
imports and use thecrypto
object instead.
Return Value
A Promise
that resolves with the generated key as a CryptoKey object or a CryptoKeyPair object.
Algorithm specific input
Throws
Example
import { crypto } from 'k6/experimental/webcrypto';
export default async function () {
const key = await crypto.subtle.generateKey(
{
name: 'AES-CBC',
length: 256,
},
true,
['encrypt', 'decrypt']
);
console.log(JSON.stringify(key));
}