Skip to main content
All Terms Glossary

Web Crypto API

Definition

The Web Crypto API provides a standardized interface for performing cryptographic operations in web applications. It offers secure random number generation, hashing, signing, and encryption capabilities. While more secure than implementing cryptography in JavaScript, proper key management and algorithm selection remain critical.

What the Web Crypto API is

The Web Crypto API is a browser-native interface, exposed through window.crypto and crypto.subtle, for performing cryptographic operations in JavaScript. It covers cryptographically strong random values via getRandomValues, plus hashing, HMAC, symmetric and asymmetric encryption, digital signatures, and key derivation through the SubtleCrypto object. The primitives are implemented in the browser engine in native code rather than in script, which is faster and less error-prone than hand-rolled JavaScript crypto. Keys are represented as CryptoKey objects that can be marked non-extractable, so the raw key material never has to be exposed to the surrounding JavaScript. Most of the API is restricted to secure contexts, meaning pages served over HTTPS or localhost.

Why it matters for security

Using a vetted native implementation removes whole classes of bugs that plague custom JavaScript cryptography, such as weak random sources, timing leaks, and incorrect algorithm plumbing. Non-extractable CryptoKey objects mean that even script running on the page cannot read the underlying bytes, which limits what a compromise can steal. However, the API does not make an application secure by itself. Poor algorithm choices, reused initialization vectors, hardcoded or badly stored keys, and mishandled outputs all undermine it. Crucially, any cryptography performed in the browser still runs in an environment an attacker may control: a cross-site scripting flaw can call the same API, use available keys, and encrypt or sign on the attacker's behalf.

How to use it safely

Choose current, well-understood algorithms and parameters, generate keys and IVs with getRandomValues, and never ship secret keys in client code. Mark keys non-extractable whenever the workflow allows, and lean on the API's key-derivation functions rather than inventing your own. Because browser-side crypto only protects data as far as the client can be trusted, keep the surrounding page free of injected script: enforce a strict Content Security Policy and sanitize inputs to shut down XSS. The Web Crypto API is a neutral web-platform primitive, so cside is not directly involved in its operation; the relevant defensive discipline is standard secure development and keeping untrusted third-party JavaScript off the page.

Definition

Should I use the Web Crypto API instead of a JavaScript crypto library?

Generally yes. Native primitives are faster, are maintained by browser vendors, and avoid many implementation pitfalls of pure-JavaScript crypto, including weak randomness. Libraries still have a place for algorithms the API lacks, but for standard hashing, encryption, and signing the built-in API is the safer default.

Definition

Does the Web Crypto API make client-side encryption fully secure?

No. It runs in the browser, an environment the user's machine and any injected script can influence. It hardens the primitives, but a cross-site scripting flaw can invoke the same API and misuse available keys. It complements, rather than replaces, transport encryption and server-side controls.

Got more questions

Talk to a security expert

We answer client-side security questions every day. Bring yours.

Book a demo

Want to walk through this with an engineer?

Thirty minutes, on your own site. Not a slide deck.

We'll show you:

Which third-party scripts are running on your site right now
Where you stand on PCI DSS 6.4.3 and 11.6.1
How much of your traffic is bots and AI agents

Rather just send a question?

Finding open slots…

Real humans only. We'd know.

Having trouble booking? Open scheduler in a new tab

What are you trying to solve?

Tell us in a line and we'll come back with something useful, not a generic pitch.

We usually help with:

Seeing which third-party scripts run on your site
PCI DSS 6.4.3 and 11.6.1 evidence
Bots, AI agents and account takeover

Prefer to just book a time? Pick a slot instead