Class: Flydata::Util::Encryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/flydata/util/encryptor.rb

Constant Summary collapse

SALT =
'ae8k9h10'

Class Method Summary collapse

Class Method Details

.decrypt(text, key, param_name = nil) ⇒ Object



15
16
17
18
19
# File 'lib/flydata/util/encryptor.rb', line 15

def decrypt(text, key, param_name = nil)
  decrypt!(text, key, param_name)
rescue => e
  text
end

.decrypt!(text, key, param_name = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/flydata/util/encryptor.rb', line 21

def decrypt!(text, key, param_name = nil)
  validate_presence(text: text, key: key)
  cipher = build_cipher(:decrypt, key)
  cipher.update(Base64.decode64(text)) + cipher.final
rescue OpenSSL::Cipher::CipherError => e
  raise "Failed to decrypt '#{param_name}' parameter. error:'#{e.to_s}'"
end

.encrypt(text, key) ⇒ Object



9
10
11
12
13
# File 'lib/flydata/util/encryptor.rb', line 9

def encrypt(text, key)
  validate_presence(text: text, key: key)
  cipher = build_cipher(:encrypt, key)
  Base64.strict_encode64(cipher.update(text) + cipher.final)
end