module EncryptFactory

Public Instance Methods

decrypt_data( encrypted_data, key, algorithm ) click to toggle source
# File lib/encrypt_factory.rb, line 13
def decrypt_data( encrypted_data, key, algorithm )
  decode = base64_decode( encrypted_data )

  decipher = OpenSSL::Cipher.new( algorithm )
  decipher.decrypt
  decipher.key = key

  decipher.update(decode) + decipher.final
end
encrypt_data( data, key, algorithm ) click to toggle source
# File lib/encrypt_factory.rb, line 3
def encrypt_data( data, key, algorithm )
  cipher = OpenSSL::Cipher.new( algorithm )
  cipher.encrypt
  cipher.key = key

  code = cipher.update(data) + cipher.final

  base64_encode( code )
end
make_signature( data, token) click to toggle source
# File lib/encrypt_factory.rb, line 23
def make_signature( data, token)
  Digest::MD5.hexdigest( data.values.map(&:to_s).sort.inject(:+) + token )
end

Private Instance Methods

base64_decode(encrypted_data) click to toggle source
# File lib/encrypt_factory.rb, line 33
def base64_decode(encrypted_data)
  Base64.decode64(encrypted_data)
end
base64_encode(code) click to toggle source
# File lib/encrypt_factory.rb, line 29
def base64_encode(code)
  Base64.encode64(code)
end