generateKey method

Returns a new Promise object which will generate a new key for use with the algorithm specified by the algorithm parameter.

Important  As of Microsoft Edge, this method returns a Promise object. See Web Cryptography API updates for more info.



var retVal = SubtleCrypto.generateKey(algorithm, extractable, keyUsages);


algorithm [in]

Type: any

An object identifying the cryptographic algorithm with which the generated key will be used (along with any required parameters).

extractable [in, optional]

Type: bool

Whether or not the keying material of the generated key may be exported by the application. The default value is false.

keyUsages [in, optional]

Type: sequence<DOMString>

An array containing one or more of the following DOM strings: encrypt, decrypt, sign, verify, derive, wrap, unwrap. This specifies the operations that the generated key will be permitted to perform.

Return value

Type: Promise

A Promise object that will return a symmetric key (Key) or an asymmetric key pair (KeyPair) object that comprises both public and private keys.

Note  IE11 returns a KeyOperation. See Web Cryptography API updates for more info.


The generateKey method supports the following cryptographic algorithms:

  • HMAC (SHA-1, SHA-256, SHA-384)
  • RSAES-PKCS1-v1_5
  • RSASSA-PKCS1-v1_5

For generateKey code examples, see the following topics:

See also