Reply
Thread Tools
Posts: 270 | Thanked: 239 times | Joined on Dec 2009 @ Czech Republic
#1
Hi I need something like this: file.list ->encrypting-> file.out and then file.out->decrypting->file.list Is there any lib or simple algorithm for it? I donīt need unbreakable code. I only need unreadable file by the common way. Thanks for your reply.
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#2
If simple compression is enough, libz contains several different algorithms to pick from.

If you want proper encryption, the OpenSSL libraries would be a good start. There are many examples of usage.
 

The Following User Says Thank You to Joorin For This Useful Post:
Posts: 1,048 | Thanked: 979 times | Joined on Mar 2008 @ SF Bay Area
#3
Google for ROT13. It's one the simplest rotational ciphers out there. Alternatively, xor every byte with a known value to encrypt and for decryption xor every byte again with the same value.
Both these methods employ security through obscurity. They do not provide any really strong encryption.
Something like Blowfish would be good if you wanted proper encryption.
There are free libraries on Bruce Schneier's website (Google for his name) that provide symmetric Blowfish encryption.
__________________
qgvdial: Google Voice client. All downloads
qgvtp: Phone integration for the n900 that dials out and sends texts using qgvdial.
mosquitto: message broker that implements the MQ Telemetry Transport protocol version 3.
qgvnotify: Google voice and contacts notifier for diablo and maemo.

If you want to thank me, click the Thanks button.
If you'd like to thank my applications, vote to move them to extras.

Last edited by uvatbc; 2010-08-12 at 15:29.
 
Posts: 21 | Thanked: 8 times | Joined on Jun 2010 @ North America, west coast
#4
Originally Posted by uvatbc View Post
Google for ROT13. It's one the simplest rotational ciphers out there.
Whoa, there! We're not that desperate, are we? ROT13 is a useless cipher that does not change word spacing, works only on letters, and is practically decipherable mentally without the need for pen and paper, if you've got any experience with it. I agree with varying degrees with your other suggestions: XOR'ing with a known value is at least not immediately readable or recognizable, and of course Blowfish libraries are better, but I think Figa needs something that is immediately usable.

Joorin is more on track with "the OpenSSL libraries", but I'll put out an actual example that can be used immediately. This has the advantage of mathematically proven strong encryption, which is the sort of thing you can't come up with by yourself.

What you want is not just "the OpenSSL libraries", but the "openssl" command itself. Do this to encrypt:

openssl enc -aes-256-cbc -salt -pass pass:MyPasswd <file.list >file.out

To decrypt, do this:

openssl enc -d -aes-256-cbc -pass pass:MyPasswd <file.out >file.list

A few notes:
- order of arguments does matter. In particular, the "-d" needs to immediately follow the "enc"
- "file.out" will be 8-bit binary unless you use the -a option for base64 output encoding, like this:

openssl enc -aes-256-cbc -salt -pass pass:MyPasswd -a <file.list >file.out
openssl enc -d -aes-256-cbc -pass pass:MyPasswd -a <file.out >file.list


- I am told that you should always use the "-salt" option when encoding, to reduce predictability. I would agree but don't have enough expertise to validate it.
- It is a bad habit to give the password on the command line. For example, if you literally use the command above to encrypt, and some other user that's logged onto your computer (or any program running on your computer) does "ps -ef | grep pass", then that line will show up complete with your very secret password. You can give the password in an environmental variable instead:

MYPASSPHRASE="Your nostrils are so big that I thought you were wearing sunglasses!"
openssl enc -aes-256-cbc -salt -pass env:MYPASSPHRASE -a <file.list >file.out


And of course for decoding:

MYPASSPHRASE="Your nostrils are so big that I thought you were wearing sunglasses!"
openssl enc -d -aes-256-cbc -pass env:MYPASSPHRASE -a <file.list >file.out


- Even environmental variables are not that secure, so you may want to use a file:

echo "Your nostrils are so big that I thought you were wearing sunglasses!" > mypass.txt
chmod 600 mypass.txt
openssl enc -aes-256-cbc -salt -pass file:mypass.txt -a <file.list >file.out


and to decode

openssl enc -d -aes-256-cbc -pass file:mypass.txt -a <file.list >file.out

Note that the password/passphrase is only read from the first line of the file, so after the first CR or LF (not sure which), everything else is ignored.

The man page for the "openssl" command does not seem to cover all of the capabilities of the command. There's probably more documentation floating out there somewhere.
 

The Following User Says Thank You to kwtm For This Useful Post:
Posts: 270 | Thanked: 239 times | Joined on Dec 2009 @ Czech Republic
#5
Thanks all. I have found this really awesome simple code for XOR. http://www.daniweb.com/code/snippet216764.html
 
Reply


 
Forum Jump


All times are GMT. The time now is 19:32.