The CryptoKey interface of the Web Crypto API represents a cryptographic key.
A CryptoKey object can be obtained using SubtleCrypto.generateKey(), SubtleCrypto.deriveKey(), SubtleCrypto.importKey(), or SubtleCrypto.unwrapKey().
Properties
CryptoKey.type-
String which may take one of the following values:
"secret": This key is a secret key for use with a symmetric algorithm."private": This key is the private half of an asymmetric algorithm'sCryptoKeyPair."public": This key is the public half of an asymmetric algorithm'sCryptoKeyPair.
CryptoKey.extractable-
Booleanindicating whether or not the key may be extracted usingSubtleCrypto.exportKey()orSubtleCrypto.wrapKey().true: The key may be extracted.falseThe key may not be extracted.exportKey()orwrapKey()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.
AesKeyGenParamsif the algorithm is any of the AES variants.RsaHashedKeyGenParamsif the algorithm is any of the RSA variants.EcKeyGenParamsif the algorithm is any of the EC variants.HmacKeyGenParamsif the algorithm is HMAC.
CryptoKey.usages-
An
Arrayof strings, indicating what can be done with the key. Possible values for array elements are:"encrypt": The key may be used toencryptmessages."decrypt": The key may be used todecryptmessages."sign": The key may be used tosignmessages."verify": The key may be used toverifysignatures."deriveKey": The key may be used inderiving a new key."deriveBits": The key may be used inderiving bits."wrapKey": The key may be used towrap a key."unwrapKey": The key may be used tounwrap 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 API The definition of 'CryptoKey' in that specification. |
Recommendation | Initial definition. |
Browser compatibility
| Desktop | Mobile | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CryptoKey | Chrome Full support 37 | Edge Full support Yes | Firefox Full support 34 | IE No support No | Opera ? | Safari No support No | WebView Android Full support 37 | Chrome Android Full support 37 | Edge Mobile Full support Yes | Firefox Android Full support 34 | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
type | Chrome Full support 37 | Edge Full support 12 | Firefox Full support 34 | IE No support No | Opera ? | Safari No support No | WebView Android Full support 37 | Chrome Android Full support 37 | Edge Mobile Full support Yes | Firefox Android Full support 34 | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
extractable | Chrome Full support 37 | Edge Full support 12 | Firefox Full support 34 | IE No support No | Opera ? | Safari No support No | WebView Android Full support 37 | Chrome Android Full support 37 | Edge Mobile Full support Yes | Firefox Android Full support 34 | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
algorithm | Chrome Full support 37 | Edge Full support 12 | Firefox Full support 34 | IE No support No | Opera ? | Safari No support No | WebView Android Full support 37 | Chrome Android Full support 37 | Edge Mobile Full support Yes | Firefox Android Full support 34 | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
usages | Chrome Full support 37 | Edge Full support 12 | Firefox Full support 34 | IE No support No | Opera ? | Safari No support No | WebView Android Full support 37 | Chrome Android Full support 37 | Edge Mobile Full support Yes | Firefox Android Full support 34 | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
See also
CryptoandCrypto.subtle.

