Web Crypto API

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

Note: This feature is available in Web Workers.

The Web Crypto API is an interface allowing a script to use cryptographic primitives in order to build systems using cryptography.

Some browsers implemented an interface called Crypto without having it well defined or being cryptographically sound. In order to avoid confusion, methods and properties of this interface have been removed from browsers implementing the Web Crypto API, and all Web Crypto API methods are available on a new interface: SubtleCrypto. The Crypto.subtle property gives access to an object implementing it.

Warning: The Web Crypto API provides a number of low-level cryptographic primitives. It's very easy to misuse them, and the pitfalls involved can be very subtle.

Even assuming you use the basic cryptographic functions correctly, secure key management and overall security system design are extremely hard to get right, and are generally the domain of specialist security experts.

Errors in security system design and implementation can make the security of the system completely ineffective.

Please learn and experiment, but don't guarantee or imply the security of your work before an individual knowledgeable in this subject matter thoroughly reviews it. The Crypto 101 Course can be a great place to start learning about the design and implementation of secure systems.

Interfaces

Crypto

Provides basic cryptography features, such as a cryptographically strong random number generator, and access to cryptographic primitives via a SubtleCrypto object. An object of this type can be accessed in the global scope using Window.crypto or WorkerGlobalScope.crypto.

SubtleCrypto

Represents an object that provides low-level cryptographic functions for key generation, encryption, decryption, key wrapping and unwrapping, and so on.

CryptoKey

Represents a cryptographic key obtained from one of the SubtleCrypto methods generateKey(), deriveKey(), importKey(), or unwrapKey().

Dictionaries

AesCbcParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.encrypt(), SubtleCrypto.decrypt(), SubtleCrypto.wrapKey(), or SubtleCrypto.unwrapKey(), when using the AES-CBC algorithm.

AesCtrParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.encrypt(), SubtleCrypto.decrypt(), SubtleCrypto.wrapKey(), or SubtleCrypto.unwrapKey(), when using the AES-CTR algorithm.

AesGcmParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.encrypt(), SubtleCrypto.decrypt(), SubtleCrypto.wrapKey(), or SubtleCrypto.unwrapKey(), when using the AES-GCM algorithm.

AesKeyGenParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.generateKey(), when generating an AES key: that is, when the algorithm is identified as any of AES-CBC, AES-CTR, AES-GCM, or AES-KW.

CryptoKeyPair

Represents a public and private key pair used for an asymmetric cryptography algorithm.

EcKeyGenParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.generateKey(), when generating any elliptic-curve-based key pair: that is, when the algorithm is identified as either of ECDSA or ECDH.

EcKeyImportParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.importKey() or SubtleCrypto.unwrapKey(), when generating any elliptic-curve-based key pair: that is, when the algorithm is identified as either of ECDSA or ECDH.

EcdhKeyDeriveParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.deriveKey(), when using the ECDH algorithm.

EcdsaParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.sign() or SubtleCrypto.verify() when using the ECDSA algorithm.

HkdfParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.deriveKey(), when using the HKDF algorithm.

HmacImportParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.importKey() or SubtleCrypto.unwrapKey(), when generating a key for the HMAC algorithm.

HmacKeyGenParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.generateKey(), when generating a key for the HMAC algorithm.

Pbkdf2Params

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.deriveKey(), when using the PBKDF2 algorithm.

RsaHashedImportParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.importKey() or SubtleCrypto.unwrapKey(), when importing any RSA-based key pair: that is, when the algorithm is identified as any of RSASSA-PKCS1-v1_5, RSA-PSS, or RSA-OAEP.

RsaHashedKeyGenParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.generateKey(), when generating any RSA-based key pair: that is, when the algorithm is identified as any of RSASSA-PKCS1-v1_5, RSA-PSS, or RSA-OAEP.

RsaOaepParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.encrypt(), SubtleCrypto.decrypt(), SubtleCrypto.wrapKey(), or SubtleCrypto.unwrapKey(), when using the RSA_OAEP algorithm.

RsaPssParams

Represents the object that should be passed as the algorithm parameter into SubtleCrypto.sign() or SubtleCrypto.verify(), when using the RSA-PSS algorithm.

Extensions to other interfaces

Window.crypto

Represents the Crypto object associated with the global object in the main thread scope.

WorkerGlobalScope.crypto

Represents Crypto object associated with the global object in worker scope.

Specifications

Specification
Web Cryptography Level 2
# crypto-interface

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
Crypto
Chrome – Full support
Chrome 11 (Release date: 2011-04-27)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 21 (Release date: 2013-05-14)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 5 (Release date: 2010-06-07)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 21 (Release date: 2013-05-14)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 5 (Release date: 2011-10-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 5 (Release date: 2011-10-12)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Partial support
Deno 1 – 1.10 (Release date: 2020-05-13)
footnote Partial support
footnote Crypto is not a concrete interface, but its methods are available on Window.crypto.
Deno – Full support
Deno 1.11 (Release date: 2021-06-08)
footnote Full support
Node.js – Partial support
Node.js 15 – 18.20 (Release date: 2020-10-20)
footnote Partial support
footnote Available as a part of the crypto module.
Node.js – Full support
Node.js 19 (Release date: 2022-10-18)
footnote Full support
getRandomValues()
Chrome – Full support
Chrome 11 (Release date: 2011-04-27)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 21 (Release date: 2013-05-14)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 5 (Release date: 2010-06-07)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 21 (Release date: 2013-05-14)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 5 (Release date: 2011-10-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 5 (Release date: 2011-10-12)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 15 (Release date: 2020-10-20)
footnote
footnote Since v17.4.0, a similar method is available via the crypto module.
randomUUID()
Chrome – Full support
Chrome 92 (Release date: 2021-07-20)
footnote Full support
Edge – Full support
Edge 92 (Release date: 2021-07-22)
footnote Full support
Firefox – Full support
Firefox 95 (Release date: 2021-12-07)
footnote Full support
Opera – Full support
Opera 78 (Release date: 2021-08-03)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 92 (Release date: 2021-07-20)
footnote Full support
Firefox for Android – Full support
Firefox for Android 95 (Release date: 2021-12-07)
footnote Full support
Opera Android – Full support
Opera Android 65 (Release date: 2021-10-20)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Full support
Samsung Internet 16 (Release date: 2021-11-25)
footnote Full support
WebView Android – Full support
WebView Android 92 (Release date: 2021-07-20)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.11 (Release date: 2021-06-08)
footnote Full support
Node.js – Full support
Node.js 16.7 (Release date: 2021-08-17)
footnote
footnote Since 14.17.0 and 15.6.0, a similar method is available via the crypto module.
subtle
Chrome – Full support
Chrome 37 (Release date: 2014-08-26)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 34 (Release date: 2014-12-01)
footnote Full support
Opera – Full support
Opera 24 (Release date: 2014-09-02)
footnote Full support
Safari – No support
Safari 7 – 11 (Release date: 2013-10-22)
prefix
footnote Removed in 11.1 and later
prefix Implemented with the vendor prefix: webkit
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 37 (Release date: 2014-09-03)
footnote Full support
Firefox for Android – Full support
Firefox for Android 34 (Release date: 2014-12-01)
footnote Full support
Opera Android – Full support
Opera Android 24 (Release date: 2014-09-10)
footnote Full support
Safari on iOS – No support
Safari on iOS 7 – 11 (Release date: 2013-09-18)
prefix
footnote Removed in 11.3 and later
prefix Implemented with the vendor prefix: webkit
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 3 (Release date: 2015-04-10)
footnote Full support
WebView Android – Full support
WebView Android 37 (Release date: 2014-09-03)
footnote Full support
WebView on iOS – No support
WebView on iOS 7 – 11 (Release date: 2013-09-18)
prefix
footnote Removed in 11.3 and later
prefix Implemented with the vendor prefix: webkit
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.11 (Release date: 2021-06-08)
footnote Full support
Node.js – Full support
Node.js 15 (Release date: 2020-10-20)
footnote Full support
Secure context required
Chrome – Full support
Chrome 60 (Release date: 2017-07-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 75 (Release date: 2020-04-07)
footnote Full support
Opera – Full support
Opera 47 (Release date: 2017-08-09)
footnote Full support
Safari – Full support
Safari 15 (Release date: 2021-09-20)
footnote Full support
Chrome Android – Full support
Chrome Android 60 (Release date: 2017-08-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 44 (Release date: 2017-12-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
Samsung Internet – Full support
Samsung Internet 8 (Release date: 2018-07-18)
footnote Full support
WebView Android – Full support
WebView Android 60 (Release date: 2017-08-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15 (Release date: 2021-09-20)
footnote Full support
Bun – No support
Bun
footnote No support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.