module Lux::Current::EncryptParams
used for encrypting and decrypting data in forms
Public Instance Methods
decrypt(hash)
click to toggle source
decrypts params starting with data
# 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)
click to toggle source
encrypt_param('dux', 'foo') <OpenStruct name=“_data_1”, value=“eyJ0eXAiOiJKV1QiLCJhbGciOi…”
# 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