Sha256: 06c54abe3e1d85d4a4b32267cdffe82a149fd89ed7eb9881dc825b1c6d648bb2

Contents?: true

Size: 733 Bytes

Versions: 6

Compression:

Stored size: 733 Bytes

Contents

module Nyauth
  class Encryptor
    include Singleton

    cattr_writer :secret, :cipher, :digest
    self.secret = ENV['ENCRYPTION_SECRET'] || '46d9a00e79b6bbf1c64a829c5640f5798c2e7c5066493f6d7e56ba800fd17d62b9e2bdf9102ae915f22eb40f5d6c83d6b3266baa509de7fc330c88bd4947bf56'
    self.cipher = 'aes-256-cbc'
    self.digest = 'SHA512'

    attr_reader :encryptor

    def initialize
      @encryptor = ::ActiveSupport::MessageEncryptor.new(@@secret, cipher: @@cipher, digest: @@digest)
    end

    class << self
      def encrypt(message)
        instance.encryptor.encrypt_and_sign(message)
      end

      def decrypt(encrypted_message)
        instance.encryptor.decrypt_and_verify(encrypted_message)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nyauth-0.2.1 lib/nyauth/encryptor.rb
nyauth-0.2.0 lib/nyauth/encryptor.rb
nyauth-0.1.0 lib/nyauth/encryptor.rb
nyauth-0.0.3 lib/nyauth/encryptor.rb
nyauth-0.0.2 lib/nyauth/encryptor.rb
nyauth-0.0.1 lib/nyauth/encryptor.rb