Sha256: d932a337fa86bd6a21523c13b78f39d521b4f52c9b66a237c8213602ae518716
Contents?: true
Size: 1006 Bytes
Versions: 24
Compression:
Stored size: 1006 Bytes
Contents
module Avo module Services class EncryptionService class << self def encrypt(...) new(...).encrypt end def decrypt(...) new(...).decrypt end end def initialize(message:, purpose:, **kwargs) @message = message @purpose = purpose @crypt = ActiveSupport::MessageEncryptor.new(encryption_key, **kwargs) end def encrypt @crypt.encrypt_and_sign(@message, purpose: @purpose) end def decrypt @crypt.decrypt_and_verify(@message, purpose: @purpose) end private def encryption_key secret_key_base[0..31] rescue # This will fail the decryption process. # It's here only to keep Avo from crashing SecureRandom.random_bytes(32) end def secret_key_base ENV["SECRET_KEY_BASE"] || Rails.application.credentials.secret_key_base || Rails.application.secrets.secret_key_base end end end end
Version data entries
24 entries across 24 versions & 1 rubygems