Module: Watobo::Crypto

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

Overview

:nodoc: all

Class Method Summary collapse

Class Method Details

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



20
21
22
23
24
25
26
# File 'lib/watobo/utils/crypto.rb', line 20

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



14
15
16
17
# File 'lib/watobo/utils/crypto.rb', line 14

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



28
29
30
31
32
33
34
# File 'lib/watobo/utils/crypto.rb', line 28

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



10
11
12
# File 'lib/watobo/utils/crypto.rb', line 10

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