TL;DR
This guide shows you how to encrypt files on your computer using tools that are probably already installed (like OpenSSL). It’s a basic method for keeping things private, but it’s not foolproof. For really important data, use more advanced encryption software.
Encrypting Files with OpenSSL
- Check if OpenSSL is Installed: Most Linux and macOS systems have OpenSSL pre-installed. Windows users might need to install it (see step 2). To check, open your terminal or command prompt and type:
openssl versionIf you see version information, you’re good to go!
- Install OpenSSL (if needed): If the above command doesn’t work on Windows, download and install OpenSSL from a reputable source. A common option is Shining Light Productions. Make sure to add the OpenSSL directory to your system’s PATH environment variable so you can use it from any command prompt window.
- Generate an Encryption Key: This key will be used to encrypt and decrypt your files. Keep this key very safe! Losing it means losing access to your data.
openssl rand -base64 32 > my_encryption_key.txtThis creates a file named
my_encryption_key.txtcontaining a random 32-byte key (which is pretty secure for basic use). - Encrypt the File: Use OpenSSL to encrypt your file.
openssl enc -aes-256-cbc -salt -in my_secret_file.txt -out my_secret_file.enc -k "your_password"Replace
my_secret_file.txtwith the name of your file andyour_passwordwith a strong password. The-aes-256-cbcoption specifies the encryption algorithm (AES with a 256-bit key),-saltadds extra security, and-k "your_password"provides the password directly on the command line. Be aware that providing the password this way is less secure than using a file or prompting for it.
Alternatively, use the key file:openssl enc -aes-256-cbc -salt -in my_secret_file.txt -out my_secret_file.enc -pass file:my_encryption_key.txt - Decrypt the File: To decrypt, use:
openssl enc -aes-256-cbc -d -salt -in my_secret_file.enc -out my_decrypted_file.txt -k "your_password"Replace
my_secret_file.encwith the encrypted file name andyour_passwordwith the password you used for encryption.
Or, using the key file:openssl enc -aes-256-cbc -d -salt -in my_secret_file.enc -out my_decrypted_file.txt -pass file:my_encryption_key.txt - Important Security Notes:
- Password Strength: Use a strong, unique password. A long passphrase is better than a short one.
- Key File Safety: Protect your
my_encryption_key.txtfile! If someone gets it, they can decrypt your files. Consider storing it on separate media (like a USB drive) and keeping that secure. - Command Line History: Your password might be saved in your command line history. Clear your history after encrypting/decrypting if you used the
-koption. - Not Perfect: This is basic encryption. It’s good for casual privacy, but not suitable for highly sensitive data. Consider dedicated cyber security software for stronger protection.