Module: Lux::Current::EncryptParams

Extended by:
EncryptParams
Included in:
EncryptParams
Defined in:
lib/lux/current/lib/encrypt_params.rb

Overview

used for encrypting and decrypting data in forms

Instance Method Summary collapse

Instance Method Details

#decrypt(hash) ⇒ Object

decrypts params starting with data



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lux/current/lib/encrypt_params.rb', line 24

def decrypt hash
  for key in hash.keys
    next unless key.starts_with?('_data_')
    data = Crypt.decrypt(hash.delete(key))
    data, value = data.split('#', 2)
    data = data.split('::')

    if data[1]
      hash[data[0]] ||= {}
      hash[data[0]][data[1]] = value
    else
      hash[data[0]] = value
    end
  end

  hash
rescue
  Lux.log ' Lux::Current::EncryptParams decrypt error'.red
  {}
end

#encrypt(name, value) ⇒ Object

encrypt_param(‘dux’, ‘foo’) <OpenStruct name=“_data_1”, value=“eyJ0eXAiOiJKV1QiLCJhbGciOi…”



10
11
12
13
14
15
# File 'lib/lux/current/lib/encrypt_params.rb', line 10

def encrypt name, value
  base = name.include?('[') ? name.split(/[\[\]]/).first(2).join('::') : name
  base += '#%s' % value

  OpenStruct.new(name: "_data_#{@cnt+=1}", value: Crypt.encrypt(base))
end

#hidden_input(name, value) ⇒ Object



17
18
19
20
21
# File 'lib/lux/current/lib/encrypt_params.rb', line 17

def hidden_input name, value
  data = encrypt name, value

  %[<input type="hidden" name="#{data.name}" value="#{data.value}" />]
end