CryptoKey
Secure context: This 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
-
A boolean value indicating whether or not the key may be extracted using
SubtleCrypto.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 toencrypt
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
.
-
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 |
---|
Web Cryptography API # cryptokey-interface |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
CryptoKey |
37 |
12 |
34 |
No |
24 |
No |
37 |
37 |
34 |
24 |
No |
3.0 |
algorithm |
37 |
12 |
34 |
No |
24 |
No |
37 |
37 |
34 |
24 |
No |
3.0 |
extractable |
37 |
12 |
34 |
No |
24 |
No |
37 |
37 |
34 |
24 |
No |
3.0 |
secure_context_required |
60 |
79 |
75 |
No |
47 |
No |
60 |
60 |
No |
47 |
No |
8.0 |
type |
37 |
12 |
34 |
No |
24 |
No |
37 |
37 |
34 |
24 |
No |
3.0 |
usages |
37 |
12 |
34 |
No |
24 |
No |
37 |
37 |
34 |
24 |
No |
3.0 |
See also
- Web Crypto API
- Web security
- Privacy, permissions, and incormation security
-
Crypto
andCrypto.subtle
.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey