class Decidim::AttributeEncryptor
Public Class Methods
cryptor()
click to toggle source
# File lib/decidim/attribute_encryptor.rb, line 21 def self.cryptor key = ActiveSupport::KeyGenerator.new("attribute").generate_key( Rails.application.secrets.secret_key_base, ActiveSupport::MessageEncryptor.key_len ) ActiveSupport::MessageEncryptor.new(key) end
decrypt(string_encrypted)
click to toggle source
# File lib/decidim/attribute_encryptor.rb, line 9 def self.decrypt(string_encrypted) return if string_encrypted.blank? # `ActiveSupport::MessageEncryptor` expects all values passed to the # `#decrypt_and_verify` method to be instances of String as the message # verifier calls `#split` on the value objects: https://git.io/JqfOO. # If something else is passed, just return the value as is. return string_encrypted unless string_encrypted.is_a?(String) cryptor.decrypt_and_verify(string_encrypted) end
encrypt(string)
click to toggle source
# File lib/decidim/attribute_encryptor.rb, line 5 def self.encrypt(string) cryptor.encrypt_and_sign(string) if string.present? end