Join our Newsletter — 33% off our NHI Course

Web Crypto API

The Web Crypto API is the browser standard interface for cryptographic operations in web applications. It provides access to digest, encryption, decryption, signature and key generation functions through native browser code, which keeps secrets and cryptographic material inside the browser runtime rather than application scripts.

What the Web Crypto API Does

The Web Crypto API gives web applications access to browser-native cryptographic primitives such as hashing, encryption, decryption, signatures and key generation. The practical importance is that sensitive operations can happen inside the browser runtime instead of being reimplemented in JavaScript, which reduces exposure to accidental weakness and malicious script manipulation.

Its value is not that it makes cryptography easy, but that it provides a standard interface with implementation details handled by the browser. That matters because cryptography fails most often when developers roll their own logic, misuse algorithms, or move secret material into application code where it is easier to leak, copy or tamper with.

Why It Matters for Web Application Security

Web Crypto is a security boundary aid, not a complete security strategy. It helps preserve confidentiality and integrity for operations performed in the browser, but it does not protect data once it leaves the browser, and it does not make insecure application logic safe. If an attacker can run script in the page, they can still abuse whatever cryptographic API the application exposes.

For that reason, Web Crypto is best understood as one part of a broader client-side security posture. It is useful for password handling, token wrapping, message authentication, local encryption, and browser-mediated key use, but the surrounding application still needs strong origin controls, content security, session handling and server-side trust decisions.

When the subject is secure browser cryptography, the most relevant design question is often whether the application should use Web Crypto directly or rely on a higher-level library and key management pattern. The browser primitive is powerful, but the surrounding design determines whether it is actually safe to use.

How It Relates to Keys and Secret Material

The most important security property of the Web Crypto API is that it can keep cryptographic operations inside the browser runtime without exposing private keys or raw secret material to normal application code. That is materially different from storing keys in JavaScript variables, embedding them in bundles, or sending them through network requests.

In practice, this means the API is useful for operations where the browser should hold or handle a key, but the application should not be able to read it directly. Examples include verifying signatures, encrypting local content, or using generated keys for browser-scoped protection. The design still requires care around exportability, persistence, origin isolation and recovery, because a browser-held key is only as safe as the environment that protects it.

The strongest implementations treat Web Crypto as a primitive layer and pair it with disciplined key generation, storage decisions and rotation planning. For general guidance on choosing misuse-resistant cryptographic approaches, see the Data Protection API Choices Guide, which places Web Crypto alongside other practical crypto options.

Common Failure Modes and Design Trade-offs

Web Crypto can still be misused even when the underlying algorithms are sound. Common failures include treating client-side crypto as a substitute for server-side access control, assuming browser encryption protects data after disclosure, and using weak integration patterns that expose keys through application logic or insecure origin contexts.

The trade-off is that browser-native cryptography improves standardisation and can reduce implementation error, but it also introduces dependency on browser behaviour, platform support and correct API usage. Some teams need algorithm agility, broader portability or stronger library-level controls than the browser alone provides. That is why crypto design should be deliberate rather than opportunistic.

For teams planning long-lived systems, crypto agility matters as much as the initial algorithm choice. The Crypto-Agility Guide is useful when a Web Crypto design must evolve without forcing a rewrite of the application’s cryptographic model.

Security Verification and Browser-Assisted Authentication

Because Web Crypto is often used in authentication, signing and key-bound browser flows, it should be validated alongside the application’s identity and session design. Teams should confirm that the browser cryptography actually supports the intended trust model, especially where proof of possession, token binding, or phishing-resistant sign-in is involved.

That becomes especially important when Web Crypto is combined with standards such as WebAuthn or FIDO2, where browser and authenticator responsibilities are split. The browser API may perform the cryptographic operation, but the security of the end-to-end ceremony depends on the relying party, the authenticator properties and the verification logic. The FIDO2 and WebAuthn Internals Guide helps place those browser cryptographic operations in their wider authentication context.

For broader control alignment, the OWASP API Security Top 10 remains a useful reference when browser-side cryptographic operations are part of an API-backed application flow, because misuse at the API boundary can undermine otherwise correct client-side crypto.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS and NIST SP 800-53 Rev 5 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.

Framework Control / Reference Relevance
OWASP ASVS V11 — Cryptography Web Crypto is a browser cryptography interface used to implement hashing, encryption, signatures and key handling.
Recommendation — Verify browser cryptography use against V11 requirements for approved algorithms, safe key handling and correct implementation.
NIST SP 800-53 Rev 5 SC-13 — Cryptographic Protection The term centers on cryptographic operations and protection of data handled in the browser runtime.
IA-5 — Authenticator Management Web Crypto often supports browser-held keys and authentication material used in login and signing flows.
Recommendation — Apply SC-13 to require approved cryptographic protection for data handled by the application. Apply IA-5 to manage cryptographic authenticators, lifecycle and rotation for browser-used secrets.
ISO/IEC 27001:2022 A.8.24 — Use of cryptography Browser-native cryptography maps directly to Annex A cryptography controls.
Recommendation — Use A.8.24 to govern approved cryptographic use, key handling and implementation consistency.