Garry Conn

How to Encode and Decode Files in Terminal

The command is very easy to remember. It should work on most all linux systems including Mac OS X. From terminal type this:

openssl base64 -in yourfile.txt -out yourfilerenamed.txt

Let's try it out, shall we? He goes: Here's the copy of yourfile.txt below:

Hello, This is a regular text file that pretty much any type of computer

system can open up and read. To make this more challenging, especially if

the message you are writing isn't something you would want everyone to see,

let's scramble it up by encoding it with base64. Good luck figuring out all

the bad things I said about you!

Now, let's encode this file to make it a little more challenging for other people to read it. Once again, enter this command:

openssl base64 -in yourfile.txt -out yourfile-encoded.txt

The command will encode your message instantly and appear in a new file called yourfile-encoded.txt You can open it and it should look like this:

SGVsbG8sIFRoaXMgaXMgYSByZWd1bGFyIHRleHQgZmlsZSB0aGF0IHByZXR0eSBt

dWNoIGFueSB0eXBlIG9mIGNvbXB1dGVyCnN5c3RlbSBjYW4gb3BlbiB1cCBhbmQg

cmVhZC4gVG8gbWFrZSB0aGlzIG1vcmUgY2hhbGxlbmdpbmcsIGVzcGVjaWFsbHkg

aWYKdGhlIG1lc3NhZ2UgeW91IGFyZSB3cml0aW5nIGlzbid0IHNvbWV0aGluZyB5

b3Ugd291bGQgd2FudCBldmVyeW9uZSB0byBzZWUsCmxldCdzIHNjcmFtYmxlIGl0

IHVwIGJ5IGVuY29kaW5nIGl0IHdpdGggYmFzZTY0LiBHb29kIGx1Y2sgZmlndXJp

bmcgb3V0IGFsbAp0aGUgYmFkIHRoaW5ncyBJIHNhaWQgYWJvdXQgeW91IQo=

Now, if you happened to stumble upon a message that looks like the above I am pretty sure you'd chalk it up as being some kind of unrecognizable system file or something related to the operating system. Never would you suspect that this gibberish would contain a secret message!

Next step is for the person who you want reading the file to decode it. That person would need to type this command in terminal:

openssl -d -in yourfile-encoded.txt -out yourfile-decoded.txt

Doing so should decode the message. Let's give it a try and see if it worked:

Hello, This is a regular text file that pretty much any type of computer

system can open up and read. To make this more challenging, especially if

the message you are writing isn't something you would want everyone to see,

let's scramble it up by encoding it with base64. Good luck figuring out all

the bad things I said about you!

It worked!

The really neat thing about this is that you can also encode grapics, pictures, videos and pretty much any type of file you want. It's not just limited to text files. So let's say that you have a naked picture of yourself and you want to share it with someone, er... special. Just repeat the same process as shown above:

openssl base64 -in naked-picture-of-me.jpg -out special-gift-for-you.jpg

The "special person" who receives this file will have to decode it before they can open it. If they try to open the encoded image, it will simply fail to open. Depending on what operating system being used the message will vary, but basically will say that the image is broke or damaged and can not be opened. The special person who you want to be able to see your naked picture will need to type this:

openssl base64 -d -in special-gift-for-you.jpg -out naked-pic-decoded.jpg

I think I'll pass on providing a real image example to show you on that last tip! Anyway, I hope that you like this little trick. Now you can send secret messages and files to all your special people with a little less stress of having others find out.