Module: Watobo::Crypto
- Defined in:
- lib/watobo/utils/crypto.rb
Overview
:nodoc: all
Class Method Summary collapse
- .decrypt(encrypted_data, pass, iv = nil, cipher_type = "AES-256-CBC") ⇒ Object
- .decryptPassword(b64_encrypted_password, secret) ⇒ Object
- .encrypt(data, pass, iv = nil, cipher_type = "AES-256-CBC") ⇒ Object
- .encryptPassword(plain_password, secret) ⇒ Object
Class Method Details
.decrypt(encrypted_data, pass, iv = nil, cipher_type = "AES-256-CBC") ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/watobo/utils/crypto.rb', line 29 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
23 24 25 26 |
# File 'lib/watobo/utils/crypto.rb', line 23 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
37 38 39 40 41 42 43 |
# File 'lib/watobo/utils/crypto.rb', line 37 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 |