Skip to content

Instantly share code, notes, and snippets.

@matteocelani
Created December 13, 2023 22:12
Show Gist options
  • Select an option

  • Save matteocelani/8e97084fb7b9ef2aa5998fb685118ba7 to your computer and use it in GitHub Desktop.

Select an option

Save matteocelani/8e97084fb7b9ef2aa5998fb685118ba7 to your computer and use it in GitHub Desktop.

Encrypt and Decrypt Files with OpenSSL

This documentation provides detailed instructions on how to use OpenSSL to encrypt and decrypt text files.

Encrypt a File

openssl enc -aes-256-cbc -salt -in path/to/your/file.txt -out path/to/your/file.enc

Enter a password when prompted. This password will be necessary to decrypt the file.

Decrypt a File

openssl enc -aes-256-cbc -d -in path/to/your/file.enc -out path/to/your/decrypted_file.txt

Enter the password used for encryption when prompted.

OpenSSL

OpenSSL is a suite of tools for communication security and cryptography, used for creating SSL/TLS certificates and for managing various cryptographic functions.

  • enc: This OpenSSL option indicates that you are using the encryption function.

  • -aes-256-cbc: Specifies the encryption algorithm. AES (Advanced Encryption Standard) with a 256-bit key in CBC (Cipher Block Chaining) mode.

  • -salt: Adds "salt" to the encryption key to improve security. The salt ensures that the keys generated are unique even if the same password is used multiple times.

  • -in: Specifies the input file (the file you want to encrypt).

  • -out: Specifies the output file (where you want the encrypted file to be saved).

  • -d: Used during decryption. Indicates to OpenSSL to decrypt the data.

Important Notes

  • These commands use the AES-256 algorithm to encrypt and decrypt the file.
  • Do not forget the password used for encryption. Without it, you will not be able to access the contents of the encrypted file.
  • Before encrypting important files, it is advisable to practice with test files to ensure you understand the process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment