Module: EncryptFactory

Included in:
CryptApi::Main
Defined in:
lib/encrypt_factory.rb

Instance Method Summary collapse

Instance Method Details

#decrypt_data(encrypted_data, key, algorithm) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/encrypt_factory.rb', line 13

def decrypt_data( encrypted_data, key, algorithm )
  code = 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) ⇒ Object



3
4
5
6
7
8
9
10
11
# 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) ⇒ Object



23
24
25
# File 'lib/encrypt_factory.rb', line 23

def make_signature( data, token)
  Digest::MD5.hexdigest( data.values.map(&:to_s).sort.inject(:+) + token )
end