This batch script allows you to encrypt or decrypt files and folders using 7-Zip.
It supports custom or default passwords and automatically deletes the original after encryption or decryption for security.
When using:
-p (password) + -mhe (encrypt headers)
7-Zip applies:
- AES-256 encryption
- CBC (Cipher Block Chaining) mode
- SHA-256 key derivation from your password
✅ Strong, modern encryption
⚠ Weak passwords (e.g., 1234) can still be brute-forced.
📂 The .7z format is open and can be decrypted with the correct password using any compatible tool.
Encrypt:
7z a -pMySecret123 -mhe locked.7z Secret.txt7z→ Runs 7-Zipa→ Add to archive-pMySecret123→ Sets password (replace with your own)-mhe→ Encrypts file nameslocked.7z→ Output archiveSecret.txt→ File to encrypt
Delete original after encrypting:
del Secret.txtDecrypt:
7z x -pMySecret123 locked.7z- Run the
.batfile. - Choose an option:
1→ Lock/Encrypt2→ Unlock/Decrypt3→ Exit
- For encryption:
- Enter full path to file/folder
- Specify
F(file) orD(folder) - Enter a password (leave blank for default)
- For decryption:
- Enter full path to
.7zarchive - Enter password (or leave blank for default)
- Enter full path to
- You must have 7-Zip installed and added to your PATH.
- The script removes the original after successful encryption/decryption.
- Encrypted archives can be opened with any tool that supports
.7zand the password.