Web/API/CryptoKey

From Get docs

Secure contextThis feature is available only in secure contexts (HTTPS), in some or all supporting browsers.


The CryptoKey interface of the Web Crypto API represents a cryptographic key obtained from one of the SubtleCrypto methods generateKey(), deriveKey(), importKey(), or unwrapKey().

For security reasons, the CryptoKey interface can only be used in a secure context.

Properties

CryptoKey.type
String which may take one of the following values:
"secret"
CryptoKey.extractable
Boolean indicating whether or not the key may be extracted using SubtleCrypto.exportKey() or SubtleCrypto.wrapKey().
true
  • The key may be extracted.
  • false The key may not be extracted. exportKey() or wrapKey() will throw an exception if used to extract this key.
CryptoKey.algorithm
An object describing the algorithm for which this key can be used and any associated extra parameters.
  • AesKeyGenParams if the algorithm is any of the AES variants.
  • RsaHashedKeyGenParams if the algorithm is any of the RSA variants.
  • EcKeyGenParams if the algorithm is any of the EC variants.
  • HmacKeyGenParams if the algorithm is HMAC.
CryptoKey.usages
An Array of strings, indicating what can be done with the key. Possible values for array elements are:
"encrypt"
  • The key may be used to encrypt messages.
  • "decrypt": The key may be used to decrypt messages.
  • "sign": The key may be used to sign messages.
  • "verify": The key may be used to verify signatures.
  • "deriveKey": The key may be used in deriving a new key.
  • "deriveBits": The key may be used in deriving bits.
  • "wrapKey": The key may be used to wrap a key.
  • "unwrapKey": The key may be used to unwrap a key.

Examples

The examples for SubtleCrypto methods often use CryptoKey objects. For example:

  • SubtleCrypto.generateKey()
  • SubtleCrypto.deriveKey()
  • SubtleCrypto.importKey()
  • SubtleCrypto.exportKey()
  • SubtleCrypto.wrapKey()
  • SubtleCrypto.unwrapKey()
  • SubtleCrypto.encrypt()
  • SubtleCrypto.decrypt()
  • SubtleCrypto.sign()
  • SubtleCrypto.verify()

Specifications

Specification Status Comment
Web Cryptography APIThe definition of 'CryptoKey' in that specification. Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
CryptoKey Chrome

Full support 37

Edge

Full support 12

Firefox

Full support 34

IE

No support No

Opera

Full support 24

Safari

No support No

WebView Android

Full support 37

Chrome Android

Full support 37

Firefox Android

Full support 34

Opera Android

Full support 24

Safari iOS

No support No

Samsung Internet Android

Full support 3.0

algorithm Chrome

Full support 37

Edge

Full support 12

Firefox

Full support 34

IE

No support No

Opera

Full support 24

Safari

No support No

WebView Android

Full support 37

Chrome Android

Full support 37

Firefox Android

Full support 34

Opera Android

Full support 24

Safari iOS

No support No

Samsung Internet Android

Full support 3.0

extractable Chrome

Full support 37

Edge

Full support 12

Firefox

Full support 34

IE

No support No

Opera

Full support 24

Safari

No support No

WebView Android

Full support 37

Chrome Android

Full support 37

Firefox Android

Full support 34

Opera Android

Full support 24

Safari iOS

No support No

Samsung Internet Android

Full support 3.0

Secure context required Chrome

Full support 60

Edge

Full support 79

Firefox

Full support 75

IE

No support No

Opera

Full support 47

Safari

No support No

WebView Android

Full support 60

Chrome Android

Full support 60

Firefox Android

No support No

Opera Android

Full support 47

Safari iOS

No support No

Samsung Internet Android

Full support 8.0

type Chrome

Full support 37

Edge

Full support 12

Firefox

Full support 34

IE

No support No

Opera

Full support 24

Safari

No support No

WebView Android

Full support 37

Chrome Android

Full support 37

Firefox Android

Full support 34

Opera Android

Full support 24

Safari iOS

No support No

Samsung Internet Android

Full support 3.0

usages Chrome

Full support 37

Edge

Full support 12

Firefox

Full support 34

IE

No support No

Opera

Full support 24

Safari

No support No

WebView Android

Full support 37

Chrome Android

Full support 37

Firefox Android

Full support 34

Opera Android

Full support 24

Safari iOS

No support No

Samsung Internet Android

Full support 3.0

Legend

Full support  
Full support
No support  
No support


See also