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"
- 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
Boolean
indicating whether or not the key may be extracted usingSubtleCrypto.exportKey()
orSubtleCrypto.wrapKey()
.
true
- The key may be extracted.
false
The 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.
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 todecrypt
messages."sign"
: The key may be used tosign
messages."verify"
: The key may be used toverify
signatures."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
.
- The key may be used to
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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
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
- Web Crypto API
- Web security
- Privacy, permissions, and incormation security
Crypto
andCrypto.subtle
.
CryptoKey by Mozilla Contributors is licensed under CC-BY-SA 2.5.