What is the Web Crypto API?
The Web Crypto API is a powerful native interface built directly into modern web browsers like Chrome, Firefox, Safari, and Edge. It provides developers with a set of low-level cryptographic primitives that allow JavaScript applications to perform complex security operations without relying on heavy third-party node modules or backend servers.
How to detect Web Crypto support in JavaScript
Before performing client-side encryption, you should always check if the browser is equipped to handle the operations. Here is a clean, dependency-free diagnostic snippet:
function isWebCryptoSupported() {
// 1. Check for basic support
const hasCrypto = window.crypto !== undefined;
const hasSubtle = hasCrypto && window.crypto.subtle !== undefined;
// 2. Check for secure context (HTTPS)
const isSecure = window.isSecureContext === true;
if (!hasSubtle) {
console.error("Native Cryptography not supported in this browser.");
return false;
}
if (!isSecure) {
console.warn("SubtleCrypto may be blocked on non-secure (HTTP) origins.");
}
return true;
}
Why is Client-Side Cryptography Important?
Traditional web applications handle security by sending plaintext data to a server, where the backend encrypts it. This architecture inherently means the server owner has access to your unencrypted data prior to encryption. By utilizing the SubtleCrypto interface, zero-knowledge platforms like ZeroKey scramble your secrets locally on your device. The server only receives a mathematically secure, unreadable blob of ciphertext, ensuring true privacy.