I have done multiple google searches and searched the mailing list. All of the solutions I found seemed kind of heavy / complicated. I just want a very simple way to encrypt and decrypt a string. Something like: encrypt("fdsfdsfdsf", "some key"); decrypt("fdsfdsfsdf", "some key"); Is this possible? Thanks for your help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ben Johnson wrote:> I have done multiple google searches and searched the mailing list. All > of the solutions I found seemed kind of heavy / complicated. I just want > a very simple way to encrypt and decrypt a string. Something like: > > encrypt("fdsfdsfdsf", "some key"); > decrypt("fdsfdsfsdf", "some key"); > > Is this possible? > > Thanks for your help.# There''s a simple solution if all you want to do is store passwords or something like that. The thing with this is that you can''t decrypt the string, because the result is a hash of what you want to encode.... But, as it always generates the same hash for the same string, you can re-encode the string and check if they are the same. require ''digest/sha1'' class Encode def initialize(key) @salt= key end def encrypt(text) Digest::SHA1.hexdigest("--#{@salt}--#{text}--") end end e= Encode.new("This is a very hard key.") pas1= e.encrypt("This is my secret password") pas2= e.encrypt("This is my secret password") pas3= e.encrypt("This is NOT my secret password") puts(pas1 == pas2) puts(pas2 == pas3) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ben Johnson wrote:> I have done multiple google searches and searched the mailing list. All > of the solutions I found seemed kind of heavy / complicated. I just want > a very simple way to encrypt and decrypt a string. Something like: > > encrypt("fdsfdsfdsf", "some key"); > decrypt("fdsfdsfsdf", "some key"); > > Is this possible? > > Thanks for your help.If you really need to decode your strings, check: http://crypt.rubyforge.org/installation.html -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ben Johnson wrote:> I have done multiple google searches and searched the mailing list. All > of the solutions I found seemed kind of heavy / complicated. I just want > a very simple way to encrypt and decrypt a string. Something like: > > encrypt("fdsfdsfdsf", "some key"); > decrypt("fdsfdsfsdf", "some key");A quick Google for "Ruby AES encrypt" reveled several examples. This one looks fine to me. (completely untested): http://brentrubyrails.blogspot.com/2007/12/aes-encryption-and-decryption-in-ruby.html -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---