A simple Java Swing text editor with built-in password-based file encryption — write and edit plain text, then optionally save it encrypted so only someone with the correct password can read it back.
Originally built as a project for a college Cryptography course, applying core concepts like symmetric encryption, key derivation, and initialization vectors to a real file format.
This README was written by AI (Claude) and reviewed by me before publishing. AI also helped write the original project's usage instructions.
- Full basic text editor: New, Open, Save, Save As, Cut/Copy/Paste, Select All, keyboard shortcuts
- Save a file as either plain text or password-encrypted
- Encrypted files use AES-CBC with a random IV generated per save, so encrypting the same text twice with the same password never produces identical ciphertext
- Opening a file automatically detects whether it's encrypted or plain text via a short header — no need to remember which
- A wrong password on an encrypted file shows a clear error instead of returning garbled text, thanks to a hash-based integrity check built into the file format
- Prompts to save unsaved changes before creating a new file, opening another file, or closing the window
Each encrypted file is built as [header][IV][ciphertext]:
- A short magic header identifies the file as encrypted, so Open can automatically tell plain text and encrypted files apart.
- The password is hashed with SHA-256 to derive an AES key.
- Before encrypting, the plaintext is combined with its own SHA-256 hash. After decrypting, that hash is recomputed and compared against the stored one — if it doesn't match, the password was wrong (or the file is corrupted), so the app can report that clearly instead of just displaying garbage text.
- A random IV (initialization vector) is generated on every save, so the same text encrypted twice never looks the same on disk.
Known limitation: the AES key is derived from a single SHA-256 hash of the password, with no salt and no iteration count. That's fine for a class exercise, but it isn't how you'd derive a key in a real product — a production implementation would use a proper password-based key derivation function like PBKDF2, bcrypt, or Argon2 with a per-file salt, to resist brute-force and rainbow-table attacks.
CryptoManager.java Encryption/decryption logic (AES-CBC, key derivation, integrity check)
FileManager.java Reading/writing files and the encrypted file format
NotepadWindow.java Swing GUI — the text editor and menus
Prerequisites: a Java JDK (8 or newer). No IDE or external libraries required — just the standard javax.crypto and javax.swing packages that ship with Java.
- Click the green Code button on this repo → Download ZIP, then unzip it on your computer (or
git cloneif you have Git installed). - Open a terminal/command prompt in that folder and compile everything:
javac *.java - Run it:
java NotepadWindow - Type or paste some text, then try File → Save As: choose "Yes" when asked about encryption to set a password and save an encrypted file, or "No" to save it as plain text. Reopen the encrypted file via File → Open to confirm the password prompt and decryption work.
A few references I used while building this:
- Java Swing / notepad tutorial
- Java Cryptography tutorial
- Building a notepad in Java (Data-Flair)
- Official Java Swing and
javax.cryptodocumentation - I also used ChatGPT to talk through the encryption design early on, but it started generating more code than I wanted, so I deliberately steered away from that and wrote the implementation myself from there.