MgenerateKey
Bun

method

crypto.webcrypto.SubtleCrypto.generateKey

extractable: boolean,
keyUsages: readonly KeyUsage[]
): Promise<CryptoKeyPair>;

Using the method and parameters provided in algorithm, subtle.generateKey() attempts to generate new keying material. Depending the method used, the method may generate either a single CryptoKey or a CryptoKeyPair.

The CryptoKeyPair (public and private key) generating algorithms supported include:

  • 'ECDH'
  • 'ECDSA'
  • 'Ed25519'
  • 'Ed448'
  • 'ML-DSA-44'
  • 'ML-DSA-65'
  • 'ML-DSA-87'
  • 'ML-KEM-512'
  • 'ML-KEM-768'
  • 'ML-KEM-1024'
  • 'RSA-OAEP'
  • 'RSA-PSS'
  • 'RSASSA-PKCS1-v1_5'
  • 'X25519'
  • 'X448'

The {CryptoKey} (secret key) generating algorithms supported include:

  • 'AES-CBC'
  • 'AES-CTR'
  • 'AES-GCM'
  • 'AES-KW'
  • 'AES-OCB'
  • 'ChaCha20-Poly1305'
  • 'HMAC'
@param keyUsages

See Key usages.

extractable: boolean,
keyUsages: readonly KeyUsage[]
): Promise<CryptoKey>;
extractable: boolean,
keyUsages: KeyUsage[]
): Promise<CryptoKey | CryptoKeyPair>;