OpenSSL

I just started playing around with Unix's OpenSSL utility. I can't seem to get the hang of it, and the man page isn't helping much. I wanted to experiment with file encryption, so I created a dummy text file with one line of text and tried to encrypt it using DES. I used the following command:

openssl des -in Encrypt.txt -out Encrypted.txt

As expected, this produced an encrypted file whose contents were illegible. Then I tried to decrypt the file. I figured since most of these encryption algorithms are based on XORing the key with the message, I would be able to apply the same command to get the original plaintext. So I used a variation of the same command.

openssl des -in Encrypted.txt -out Decrypted.txt

I opened the file Decrypted.txt and found that it was still illegible. I hadn't gotten the original plaintext back. "Okay," I thought, "I guess I don't know much about how to use DES, since it's a block cypher. Maybe I'll try a stream cypher, since I'm more familiar with how they work, and I know for a fact that for a stream cypher, encryption and decryption use the same algorithm."

I used the following commands:

openssl rc4 -in Encrypt.txt -out Encrypted.txt
openssl rc4 -in Encrypted.txt -out Decrypted.txt

Still doesn't work.

Then I noticed something strange when looking at the files. The encryption algorithm had added a human-readable prefix to the encrypted file, reading "Salted__". So it looks like what happened was the encryption algorithm added that prefix, when meant that when the same algorithm was applied again, it had a different starting point, so when it started decrypting the original message, after XORing the first eight bytes of the key with the prefix, it would be XORing a completely different part of the key with the same characters, resulting in a gibberish result.

So my question is, what is the proper way to encrypt and decrypt files using OpenSSL? Can anyone point me to any good tutorials? Because, as I said, the man page isn't providing much help.

How about using the -d option? ( -e is the default)

1 Like

Thank you. That works.