Class: EncryptData::Crypt

Inherits:
Object
  • Object
show all
Defined in:
lib/encrypt_data/crypt.rb

Direct Known Subclasses

Convert

Constant Summary collapse

ALGO =
'aes-256-cbc'.freeze

Class Method Summary collapse

Class Method Details

.crypt(cipher_method, value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/encrypt_data/crypt.rb', line 20

def crypt(cipher_method, value)
  cipher = OpenSSL::Cipher.new(ALGO)
  cipher.send(cipher_method)
  cipher.pkcs5_keyivgen(encryption_key)
  result = cipher.update(value)
  result << cipher.final
end

.decrypt(value, key) ⇒ Object



9
10
11
12
# File 'lib/encrypt_data/crypt.rb', line 9

def decrypt(value, key)
  @key = key
  crypt(:decrypt, value)
end

.encrypt(value, key) ⇒ Object



4
5
6
7
# File 'lib/encrypt_data/crypt.rb', line 4

def encrypt(value, key)
  @key = key
  crypt(:encrypt, value)
end

.encryption_keyObject



14
15
16
17
# File 'lib/encrypt_data/crypt.rb', line 14

def encryption_key
  @master_key = ENV['EncryptDataKey'].nil? ? EncryptData.configuration.master_key : ENV['EncryptDataKey']
  @key || @master_key
end