Vanilla JavaScript Projects

Project 30, Security and auth

Secure File Encryptor

Drop any file, pick a password, and download a locked copy. Only someone with the password can open it again, and the file never leaves your computer.

Encryption
AES-GCM 256
Key from
PBKDF2, 600k rounds
Dependencies
None
Your browser
Checking

Lock or unlock a file

Drop any file here
or click to choose.
Choose a file

Inside a .locked file

This is the exact layout the page writes and reads.

VJLENC 6 bytesversion 1 bytesalt 16 bytesIV 12 bytesciphertext: name length, name, file bytes, 16 byte tag

Losing the password means losing the file. There is no reset and no back door.

How it works

  1. Make a keyA random 16 byte salt and your password go through PBKDF2 to make an AES key.
  2. EncryptThe file name and bytes are encrypted together with AES-GCM and a random 12 byte IV.
  3. Pack the fileOutput is a header (magic word, version, salt, IV) followed by the ciphertext. Unlocking reads the header back.
const MAGIC = new TextEncoder().encode("VJLENC");
const salt = crypto.getRandomValues(new Uint8Array(16));
const iv = crypto.getRandomValues(new Uint8Array(12));
const key = await deriveKey(password, salt);          // PBKDF2, 600k rounds

const plain = new Uint8Array(await file.arrayBuffer());
const cipher = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, plain);

const locked = new Blob([MAGIC, new Uint8Array([1]), salt, iv, cipher]);
// Unlock: read the header back, derive the same key, decrypt()