Module: Settlebox::Crypt

Defined in:
lib/settlebox/crypt.rb

Class Method Summary collapse

Class Method Details

.aes(key, string) ⇒ Object



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

def self.aes(key, string)
  key = Array(key).pack 'H*'
  cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
  cipher.encrypt
  cipher.key = key
  cipher.iv = initialization_vector = cipher.random_iv
  cipher_text = cipher.update(string)
  cipher_text << cipher.final
  return initialization_vector + cipher_text
end

.encrypt(string, key) ⇒ Object



8
9
10
# File 'lib/settlebox/crypt.rb', line 8

def self.encrypt(string, key)
  Base64.encode64(aes(key, string)).gsub /\s/, ''
end