Sha256: a865b9bd4076f45724e53c8ade5a57efee847c19201de845e49b5fca683a0479
Contents?: true
Size: 929 Bytes
Versions: 35
Compression:
Stored size: 929 Bytes
Contents
# frozen_string_literal: true module Decidim class AttributeEncryptor def self.encrypt(string) cryptor.encrypt_and_sign(string) if string.present? end 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 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 end end
Version data entries
35 entries across 35 versions & 1 rubygems