Showing posts with label Encryption. Show all posts
Showing posts with label Encryption. Show all posts

Monday, August 26, 2013

Using openssl to encrypt/decrypt text

Here's a simple example of using the Linux openssl command to encrypt typed text data into a file and then extract it back from the file afterwards. We'll use the AES-128 encryption algorithm for this example and ask openssl to base64 encode the encrypted data afterwards, so it can be happily stored in a text file.

First, let's encrypt a test string into the file /tmp/myEncryptedData.txt:

$ openssl enc -aes128 -a -out /tmp/myEncryptedData.txt
enter aes-128-cbc encryption password: your-desired-password-here
Verifying - enter aes-128-cbc encryption password: your-desired-password-here

This is the data I'm protecting ya know!


Note: To terminate the input type a couple of Ctrl-D characters.


Now, let's read the encrypted text from /tmp/myEncryptedData.txt and display the original string back:

$ openssl enc -d -a -aes128 -in /tmp/myEncryptedData.txt
enter aes-128-cbc decryption password: your-desired-password-here
This is the data I'm protecting ya know!


Cool, huh?