GodTunnel
Files & Everyday MathGodTunnel Engineering··8 min read

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.

Cryptographic building blocks used in browser-local security utilities
PrimitiveRole in WorkflowWhy It Matters
crypto.getRandomValues()Random salts, IVs, passwords, and PINsUses OS CSPRNG without modulo bias via rejection sampling
PBKDF2 (200k rounds)Derives key material from passphraseSlows brute-force guessing attacks against weak passwords
AES-256-GCMAuthenticated file and text encryptionGuarantees wrong passphrases or tampered bytes fail decryption
SHA-256 / SHA-512Streaming multi-chunk file verificationVerifies 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.

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