W3cubDocs

/DOM

SubtleCrypto

The SubtleCrypto interface represents a set of cryptographic primitives. It is available via the Crypto.subtle properties available in a window context (via Window.crypto).

Per the spec: "Developers making use of the SubtleCrypto interface are expected to be aware of the security concerns associated with both the design and implementation of the various algorithms provided. The raw algorithms are provided in order to allow developers maximum flexibility in implementing a variety of protocols and applications, each of which may represent the composition and security parameters in a unique manner that necessitate the use of the raw algorithms."

Properties

This interface neither inherits, nor implements, any property.

Methods

This interface doesn't inherit any method.

SubtleCrypto.encrypt()
Returns a Promise of the encrypted data corresponding to the clear text, algorithm and key given as parameters.
SubtleCrypto.decrypt()
Returns a Promise of the clear data corresponding to the encrypted text, algorithm and key given as parameters.
SubtleCrypto.sign()
Returns a Promise of the signature corresponding to the text, algorithm and key given as parameters.
SubtleCrypto.verify()
Returns a Promise of a Boolean value indicating if the signature given as parameter matches the text, algorithm and key also given as parameters.
SubtleCrypto.digest()
Returns a Promise of a digest generated from the algorithm and text given as parameters.
SubtleCrypto.generateKey()
Returns a Promise of a newly generated CryptoKey, for symmetrical algorithms, or a CryptoKeyPair, containing two newly generated keys, for asymmetrical algorithm, that matches the algorithm, the usages and the extractability given as parameters.
SubtleCrypto.deriveKey()
Returns a Promise of a newly generated CryptoKey derived from a master key and a specific algorithm given as parameters.
SubtleCrypto.deriveBits()
Returns a Promise of a newly generated buffer of pseudo-random bits derived from a master key and a specific algorithm given as parameters.
SubtleCrypto.importKey()
Returns a Promise of a CryptoKey corresponding to the format, the algorithm, the raw key data, the usages and the extractability given as parameters.
SubtleCrypto.exportKey()
Returns a Promise of a buffer containing the key in the format requested.
SubtleCrypto.wrapKey()
Returns a Promise of a wrapped symmetric key for usage (transfer, storage) in insecure environments. The wrapped buffer returned is in the format given in parameters, and contains the key wrapped by the given wrapping key with the given algorithm.
SubtleCrypto.unwrapKey()
Returns a Promise of a CryptoKey corresponding to the wrapped key given in parameter.

Specifications

Specification Status Comment
Web Cryptography API
The definition of 'SubtleCrypto' in that specification.
Recommendation Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11 24 10.1
10.1
7
Prefixed
Prefixed Implemented with the vendor prefix: WebKit
encrypt 37 12
12
Not supported: AES-CTR.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns CryptoOperation instead of Promise
24 7
decrypt 37 12
12
Not supported: AES-CTR.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns CryptoOperation instead of Promise
24 7
sign 37 12
12
Not supported: RSA-PSS, ECDSA.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns CryptoOperation instead of Promise
24 7
verify 37 12
12
Not supported: RSA-PSS, ECDSA.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns CryptoOperation instead of Promise
24 7
digest 37 12
12
Not supported: SHA-1.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns CryptoOperation instead of Promise
24 7
generateKey 37 12
12
Not supported: RSA-PSS, ECDSA, ECDH.
Not supported: AES-CTR.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns KeyOperation instead of Promise
24 7
deriveKey 37 12
12
Not supported: ECDH.
Not supported: HKDF, PBKDF2.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No 24 7
deriveBits 37 12
12
Not supported: ECDH.
Not supported: HKDF, PBKDF2.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No 24 7
importKey 37 12
12
Not supported: RSA-PSS, ECDSA, ECDH.
Not supported: AES-CTR, HKDF, PBKDF2.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns KeyOperation instead of Promise
24 7
exportKey 37 12
12
Not supported: RSA-PSS, ECDSA, ECDH.
Not supported: AES-CTR.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns KeyOperation instead of Promise
24 7
wrapKey 37 12
12
Not supported: AES-CTR.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns KeyOperation instead of Promise
24 7
unwrapKey 37 12
12
Not supported: AES-CTR.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns KeyOperation instead of Promise
24 7
Available in workers ? No 48 ? ? ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 10.1
10.1
7
Prefixed
Prefixed Implemented with the vendor prefix: WebKit
6.0
encrypt 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
decrypt 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
sign 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
verify 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
digest 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
generateKey 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
deriveKey 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
deriveBits 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
importKey 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
exportKey 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
wrapKey 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
unwrapKey ? 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0
Available in workers ? ? ? ? ? ? ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto