Encrypting Files in the Browser with AES-256-GCM, SHA-256 Checksums, and WebRTC P2P
Learn how client-side WebCrypto AES-256-GCM encryption, PBKDF2 key derivation, SHA-256 checksums, and WebRTC P2P transfers protect sensitive files.
Quick summary
The browser WebCrypto API implements hardware-accelerated AES-256-GCM authenticated encryption and SHA-256 hashing natively without external libraries or server access. Pairing PBKDF2 key stretching with unique 96-bit random IVs ensures ciphertext confidentiality and tamper detection, while WebRTC DataChannels stream large files directly between devices.
How browser AES-256-GCM protects files against snooping and tampering
Encrypting a file safely requires two guarantees: nobody without the passphrase can read the bytes (confidentiality), and nobody can silently flip bits in the encrypted payload (integrity). Legacy block cipher modes like AES-CBC lack built-in authentication, leaving envelopes vulnerable unless paired carefully with an HMAC tag.
AES-256-GCM combines counter-mode encryption with Galois message authentication in a single standard WebCrypto primitive. Every encrypted envelope starts with a fresh 16-byte random salt fed into PBKDF2-SHA-256 with 200,000 iterations to stretch human passphrases into a 256-bit key, paired with a unique 12-byte initialization vector generated via crypto.getRandomValues(). Even encrypting the same file twice with the same passphrase yields completely distinct ciphertext.
| Primitive | Role in Workflow | Why It Matters |
|---|---|---|
| crypto.getRandomValues() | Random salts, IVs, passwords, and PINs | Uses OS CSPRNG without modulo bias via rejection sampling |
| PBKDF2 (200k rounds) | Derives key material from passphrase | Slows brute-force guessing attacks against weak passwords |
| AES-256-GCM | Authenticated file and text encryption | Guarantees wrong passphrases or tampered bytes fail decryption |
| SHA-256 / SHA-512 | Streaming multi-chunk file verification | Verifies ISO downloads and backups in 4 MB memory slices |
Streaming checksums and handling large backups cleanly
Downloading operating system ISOs, firmware packages, or encrypted offsite archives carries the risk of silent bit corruption or supply-chain tampering. Computing SHA-256, SHA-512, SHA-1, and MD5 digests across 4 MB File.slice() chunks lets the browser verify multi-gigabyte installers steadily without spiking RAM usage.
When email gateways or team chat tools enforce 25 MB attachment caps, slicing a large archive at the byte boundary via File.slice() splits the file instantaneously with zero extra compression overhead, and rejoining those numbered .part files restores the original binary bit-for-bit.
Direct peer-to-peer transfer over WebRTC DataChannels
Sending a confidential release artifact to a colleague often does not require permanent cloud hosting. WebRTC establishes an encrypted DTLS transport directly between two browsers using ICE candidate negotiation over lightweight copy-paste SDP codes or QR codes, with no intermediate server storing a single chunk of your payload.
For best transfer reliability behind strict corporate NATs, keep both browser tabs active during streaming, monitor buffered backpressure thresholds on the DataChannel, and verify the received size matches the source checksum when moving mission-critical binaries.
Frequently asked questions
- Can anyone recover an AES-256-GCM encrypted .gtenc file if I forget the passphrase?
- No. Neither GodTunnel nor any backend stores your passphrase or key material. Always store generated passphrases inside a trusted password manager before closing the tab.
- Why does streaming checksum hashing avoid freezing the browser?
- Reading 4 MB slices sequentially with File.slice() prevents allocating a multi-gigabyte ArrayBuffer in a single call, keeping memory flat and responsive.
- Do random password generators avoid modulo bias?
- Yes. Rejection sampling discards random 32-bit integers above the largest multiple of the character pool length, ensuring every character has an identical selection probability.
Explore category hubs
More technical guides
How to Redact, Merge, and Compress Sensitive PDFs Without Server Uploads
A practical technical guide to true browser-side PDF redaction, lossless page merging, AES-256 protection, and compression ratios without uploading files.
Documents & MediaWebP vs AVIF vs PNG vs SVG: Choosing the Right Web Image Format for Speed and Quality
Compare WebP, AVIF, PNG, JPEG, and SVG compression trade-offs, transparency support, and Core Web Vitals LCP optimization rules for fast sites.
Code & DataDebugging APIs Locally: Inspecting JWTs, Converting cURL to Fetch, and Generating TypeScript Types
Inspect production JWT tokens locally, test regular expressions, translate cURL commands to Fetch or Axios, and generate TypeScript types.