Module: Lorj::SSLCrypt

Defined in:
lib/core/core_setup_encrypt.rb

Overview

SSL Encryption feature for Lorj.

Class Method Summary collapse

Class Method Details

.encrypt_value(value, entr) ⇒ Object

Function to encrypt a data with a entr key.

return:

  • value : encrypted value in Base64 encoded data.



85
86
87
88
89
90
91
92
93
94
# File 'lib/core/core_setup_encrypt.rb', line 85

def self.encrypt_value(value, entr)
  Base64.strict_encode64(
    Encryptor.encrypt(
      :value => value,
      :key => entr[:key],
      :iv => Base64.strict_decode64(entr[:iv]),
      :salt => entr[:salt]
    )
  )
end

.get_encrypted_value(enc_value, entr, sDesc) ⇒ Object

internal runtime function for process call #_build_hdata and #_get_encrypted_value_hidden Get encrypted value

parameters:

- +default+     : encrypted default value
- +entropy+     : Entropy Hash
- +sDesc+       : data description

return:

  • value : decrypted value.

raise:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/core/core_setup_encrypt.rb', line 64

def self.get_encrypted_value(enc_value, entr, sDesc)
  return '' if enc_value.nil?
  begin
    Encryptor.decrypt(
      :value => Base64.strict_decode64(enc_value),
      :key => entr[:key],
      :iv => Base64.strict_decode64(entr[:iv]),
      :salt => entr[:salt]
    )
  rescue => e
    PrcLib.error("Unable to decrypt your %s.\n"\
                 "%s\n"\
                 ' You will need to re-enter it.',
                 sDesc, e)
  end
end

.new_encrypt_key(key = rand(36**10).to_s(36)) ⇒ Object

internal runtime function to create a new key parameters:

- +new+       : true to create a new key.

return:

- entropy: Hash. Entropy data used as key to encrypt values.
  Details from encryptor's gem.
  - :key: password
  - :salt : String current time number
  - :iv: Base64 random iv


41
42
43
44
45
46
47
48
# File 'lib/core/core_setup_encrypt.rb', line 41

def self.new_encrypt_key(key = rand(36**10).to_s(36))
  random_iv = OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv
  {
    :key => key,
    :salt => Time.now.to_i.to_s,
    :iv => Base64.strict_encode64(random_iv)
  }
end