views:

337

answers:

4

Hi,

I need to encrypt a string (from a text area) that will also be decrypted later on when it is displayed.

I'm not to concerned about it being majorly secure, but just don’t want to store the data in plain text format.

Does anyone have any suggestions on how to do this easily in rails?

Thanks, Jon

+3  A: 

Is there a ROT13 implementation in Ruby/Rails (there must be...) that's totally insecure except to human readers (and idiot savants) so seems to fit your use case.

EDIT - This is a good start for swapping out characters:

$_.tr! "A-Za-z", "N-ZA-Mn-za-m";

It asks for user input then swaps the characters.

EDIT If you're not familiar, ROT13 assigns each letter its natural number. A=1, B=2, etc. Then it adds 13 to each number, effectively spinning it half way around the alphabet. The halfway bit is great, because unlike, say, ROT12, you can just run ROT13 again to decode. One function for both. OR you could run ROT12 13 times I guess (12 * 13 = 156. 156/26 = 6.) ROT 13 is better for this though.

Alex Mcp
+1 for effective and amusing.
cjstehno
Just don't think that double-ROT13 is more secure like double-RSA might be.
tadman
+1 for making me laugh...@ Alex McP and tadman XD
Xorlev
+1 I had to smile reading the ROT12 13 times part :)
Shyam
+3  A: 

There is a RubyGem named Crypt that provides a pure Ruby implementation of a number of encryption algorithms.

John Topley
+1 Exactly what I was looking for.
Shyam
+1  A: 

If you're not concerned about security you can just base64-encode your string:

encoded = Base64::encode(string)
decoded = Base64::decode(encoded)

By the way it's also suitable for encoding binary data.

neutrino
-1 Encoding is not encryption.
Shyam
+3  A: 
gem install encryptor

It wraps the standard Ruby OpenSSL library and allows you to use any of its algorithms.

http://github.com/shuber/encryptor

Sean Huber