How to Encrypt a File With a Password
You need to email a tax document, store a credentials file, or hand off a database dump — and you want it locked so only someone with the password can open it. Password-based file encryption solves this, and you have several good options depending on whether you want zero installs, command-line control, or archive compatibility.
This guide covers four practical methods and the tradeoffs that matter: password strength, file format compatibility, and whether tampering is detected.
How Password Encryption Actually Works
You don't encrypt a file with a password directly. AES needs a fixed-length key (256 bits), not a human password. So every tool does two steps:
- Key derivation — stretch your password into a proper encryption key using a function like PBKDF2, scrypt, or Argon2, combined with a random salt.
- Encryption — use that derived key with AES-256 (typically in GCM or CBC mode) to encrypt the file.
Key derivation slows offline password guessing, but it cannot rescue a weak password. A tool that skips a suitable KDF (or uses a fast single hash) is easier to attack. See OWASP's password storage guidance for why work factors and salts matter.
Method 1 — In Your Browser (No Install)
For a one-off file, the File Encrypt/Decrypt tool uses Web Crypto AES-256-GCM with a random salt and IV and PBKDF2-SHA256 with 100,000 iterations. The selected file is processed locally; the tool does not upload it for encryption. Use a long, unique password and a trusted device and browser. The downloaded .enc file is a DevDecode-specific format, so recipients need this tool or a compatible implementation to decrypt it.
To decrypt, the recipient opens the same tool, selects the encrypted file, and enters the password. For short text rather than whole files, the AES Encrypt/Decrypt tool does the same thing for a pasted string.
Method 2 — OpenSSL (Command Line)
If OpenSSL is installed, this command encrypts a file with AES-256-CBC:
# Encrypt
openssl enc -aes-256-cbc -salt -pbkdf2 -iter 600000 \
-in secret.pdf -out secret.pdf.enc
# Decrypt
openssl enc -d -aes-256-cbc -pbkdf2 -iter 600000 \
-in secret.pdf.enc -out secret.pdf
It'll prompt for the password. The flags matter:
-saltadds a random salt (default, but be explicit).-pbkdf2uses a real key-derivation function instead of the legacy weak one.-iter 600000sets the iteration count high enough to slow brute force.
Keep -pbkdf2 and -iter on both commands. Without them, openssl enc uses a legacy key-derivation path with a much lower cost for password guessing.
OpenSSL's enc command does not support AES-GCM. The CBC command above does not authenticate the ciphertext, so it cannot provide the same tamper detection as the browser tool's GCM format. It is also not compatible with DevDecode's .enc files. See the OpenSSL enc documentation.
Method 3 — 7-Zip (Encrypted Archive)
For something a non-technical recipient can open, an encrypted ZIP/7z archive is hard to beat — 7-Zip is free and uses AES-256:
# Encrypt into an AES-256 archive (prompts for password)
7z a -p -mhe=on secret.7z secret.pdf
-pprompts for a password.-mhe=onencrypts the file names too, not just contents (7z format only).
The recipient just double-clicks and enters the password. Avoid the legacy "ZipCrypto" method some tools default to — it's broken; insist on AES-256.
Method 4 — GPG (Symmetric Mode)
GPG is usually associated with public keys, but it has a symmetric (password) mode that's excellent for files:
# Encrypt
gpg --symmetric --cipher-algo AES256 secret.pdf
# → produces secret.pdf.gpg
# Decrypt
gpg --decrypt secret.pdf.gpg > secret.pdf
GPG handles salt, key derivation, and integrity automatically, and the .gpg format is widely supported across platforms.
The Password Is the Weak Link
These methods use different formats and protections. Password guessing is a major risk, but so are compromised devices, mishandled keys, and unauthenticated ciphertext. An attacker holding the encrypted file can attempt password guesses offline; the number of guesses depends on the KDF, work factor, and their hardware.
That means:
- Use a long, random password. A 6-character password falls in seconds regardless of AES. Generate a strong one with the Password Generator — aim for 16+ characters or a 5–6 word passphrase.
- Don't reuse a password you've used elsewhere; a leak from another site hands over your file.
- Transmit the password out-of-band. Don't email the encrypted file and the password in the same thread. Send one by email and the other by text or a password manager share.
Verify Integrity
After transferring a file, a SHA-256 hash can detect accidental changes if you compare it with a value received through a trusted channel. A hash posted next to a file is not authentication: someone who can replace both can forge the comparison. AES-GCM and authenticated archive formats can detect unauthorized modifications when the decryption key remains secret.
Quick Reference
- AES-256 encrypts the file; a KDF (PBKDF2/scrypt/Argon2) + salt turns your password into the key.
- Browser, no install: File Encrypt/Decrypt — runs locally, file never uploaded.
- CLI:
openssl enc -aes-256-cbc -pbkdf2 -iter 600000(always include-pbkdf2). - Shareable archive:
7z a -p -mhe=onwith AES-256, not ZipCrypto. - Use a long, unique password from the Password Generator, share it separately, and retain a secure backup. A lost password cannot be recovered.