Hi,
2012/12/20 IƱaki Baz Castillo <[email protected]>:
> Hi, basically I receive a string generated by a user, then "encode" it
> using some secret string I own and pass the result to other user, and
> when I receive such a resulting string I must be able to decode it
> using my secret string (but no other should be able to decode the
> resulting string without knowing my secret key. This is:
>
>
> original_string = "test"
>
> secret_key = "ABCD"
>
> modified_string = HASH_FUNCTION(original_string, secret_key)
>
> original_string = UNHASH_FUNCTION(modified_string, secret_key)
>
>
> Any suggestion for the above HASH_FUNCTION and UNHASH_FUNCTION? I
> would like it to be something really efficient.
>
> Thanks a lot.
>
You can use openssl module something like this:
def encrypt(input,key)
require 'openssl'
des = OpenSSL::Cipher::Cipher.new("des-ede-cbc")
des.encrypt
des.key= "%16s" % key
des.update(input)+des.final
end
def decrypt(input,key)
require 'openssl'
des = OpenSSL::Cipher::Cipher.new("des-ede-cbc")
des.decrypt
des.key = "%16s" % key
des.update(input)+des.final
end
But, I am not sure it is really efficient.
Regards,
Park Heesob
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en