From: "Pål Bergström" Date: 2009-05-03T22:44:15+09:00 Subject: Re: OpenSSL::Cipher dad decrypt Eleanor McHugh wrote: > On 2 May 2009, at 21:45, P�l Bergstr�m wrote: > Show us the code you're actually using and we can make constructive > suggestions :) > Also whilst the particular techniques may or may not be applicable, > you can find some examples of doing OpenSSL crypto in the > presentations linked in my sig: the Semantic DNS presentation has a > substantial example (using AES). > > This is what I use. Would be good if I could catch the error and prevent it from "hanging" the browser with an error (using Rails). --- require 'openssl' require 'digest/sha2' require 'cgi' module Crypto def self.encrypt(plain_text) cgi = CGI.new("html3") passo = cgi.cookies["thecookie"].to_s c = OpenSSL::Cipher::Cipher.new("aes-256-cbc") c.encrypt c.key = key = Digest::SHA2.digest(passo) e = c.update(plain_text) e << c.final e = Base64.b64encode(e) return e end def self.decrypt(cstring) cgi = CGI.new("html3") passo = cgi.cookies["thecookie"].to_s etext = Base64.decode64(cstring) c = OpenSSL::Cipher::Cipher.new("aes-256-cbc") c.decrypt c.key = key = Digest::SHA2.digest(passo) d = c.update(etext) d << c.final return d end end -- Posted via http://www.ruby-forum.com/.