Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
generateKey
The generateKey()
generates a new cryptographic key and returns it as a CryptoKey object that can be used with the Web Crypto API.
Usage
generateKey(algorithm, extractable, keyUsages)
Parameters
Return Value
A Promise
that resolves with the generated key as a CryptoKey object.
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));
}