Module: Watobo::Crypto

Defined in:
lib/watobo/utils/crypto.rb

Class Method Summary collapse

Class Method Details

.decrypt(encrypted_data, pass, iv = nil, cipher_type = "AES-256-CBC") ⇒ Object



40
41
42
43
44
45
46
# File 'lib/watobo/utils/crypto.rb', line 40

def Crypto.decrypt(encrypted_data, pass, iv=nil, cipher_type="AES-256-CBC")
  aes = OpenSSL::Cipher::Cipher.new(cipher_type)
  aes.decrypt
  aes.key = Digest::SHA256.digest(pass)
  aes.iv = iv if iv != nil
  aes.update(encrypted_data) + aes.final  
end

.decryptPassword(b64_encrypted_password, secret) ⇒ Object



34
35
36
37
# File 'lib/watobo/utils/crypto.rb', line 34

def Crypto.decryptPassword(b64_encrypted_password, secret)
ep = Base64.decode64(b64_encrypted_password)
decrypt(ep, secret)
end

.encrypt(data, pass, iv = nil, cipher_type = "AES-256-CBC") ⇒ Object



48
49
50
51
52
53
54
# File 'lib/watobo/utils/crypto.rb', line 48

def Crypto.encrypt(data, pass, iv=nil, cipher_type="AES-256-CBC")
  aes = OpenSSL::Cipher::Cipher.new(cipher_type)
  aes.encrypt
  aes.key = Digest::SHA256.digest(pass)
  aes.iv = iv if iv != nil
  aes.update(data) + aes.final      
end

.encryptPassword(plain_password, secret) ⇒ Object



30
31
32
# File 'lib/watobo/utils/crypto.rb', line 30

def Crypto.encryptPassword(plain_password, secret)
  Base64.encode64(Crypto.encrypt(plain_password, secret)).strip
end