Advertisement
miguelcl

Simple FIle Encryption with OpenSSL

Oct 1st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.62 KB | None | 0 0
  1. Simple File Encryption with OpenSSL
  2. December 12, 2007
  3. Linux has plenty of powerful encryption software, but what can you use if you just want to secure a couple files quickly? The OpenSSL toolkit works well for this. It comes installed with Ubuntu and can provide stronger encryption than you would ever need.
  4.  
  5. This is the basic command to encrypt a file:
  6.  
  7. openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.enc
  8. How does this work?
  9.  
  10. openssl is the command for the OpenSSL toolkit.
  11. aes-256-cbc is the encryption cipher to be used. (256bit AES is what the United States government uses to encrypt information at the Top Secret level.)
  12. -a means that the encrypted output will be base64 encoded, this allows you to view it in a text editor or paste it in an email. This is optional.
  13. -salt adds strength to the encryption and should always be used.
  14. -in secrets.txt specifies the input file.
  15. -out secrets.txt.enc specifies the output file.
  16. You will be prompted for a password.
  17. It’s not much use unless you can decrypted it:
  18.  
  19. openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new
  20. -d decrypts data.
  21. -a tells OpenSSL that the encrypted data is in base64.
  22. -in secrets.txt.enc specifies the data to decrypt.
  23. -out secrets.txt.new specifies the file to put the decrypted data in.
  24. Try out OpenSSL by decrypting this string (the password is pass):
  25.  
  26. U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A=
  27. You can paste it into a text file and use the commands above, or use this command instead:
  28.  
  29. echo U2FsdGVkX18YcWkbmhsN7M/MP1E+GLf4IqmNsa53T+A= | openssl aes-256-cbc -d -a
  30. See the OpenSSL man page for more detail on what it can do.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement