Skip to content

Instantly share code, notes, and snippets.

@andyjeffries
Created May 20, 2009 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyjeffries/114796 to your computer and use it in GitHub Desktop.
Save andyjeffries/114796 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'digest/sha1'
class Test
def self.decrypt(content, password)
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
cipher.decrypt
cipher.key = Digest::SHA1.hexdigest(password)
cipher.update(content)
cipher.final
end
def self.encrypt(content, password)
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
cipher.encrypt
cipher.key = Digest::SHA1.hexdigest(password)
cipher.update(content)
cipher.final
end
end
CONFIRMATION_STRING = "09i0jsn-9fu320h3n2hf0h"
enc = Test.encrypt(CONFIRMATION_STRING, 'bar')
dec = Test.decrypt(enc, 'bar')
puts CONFIRMATION_STRING, " == ", dec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment