Sha256: 557cb7c6cf6ef3264d14bd842094e6af6e5e077ea59a92b69e8514dcc1250ae0

Contents?: true

Size: 734 Bytes

Versions: 21

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

module Auther
  # Manages encryption/decryption.
  class Cipher
    BYTE_DIVISOR = 2

    def self.generate login, password
      secret = SecureRandom.hex key_length / BYTE_DIVISOR
      cipher = new secret

      {
        secret: secret,
        login: cipher.encrypt(login),
        password: cipher.encrypt(password)
      }
    end

    def self.key_length
      ActiveSupport::MessageEncryptor.key_len
    end

    def initialize secret
      @encryptor = ActiveSupport::MessageEncryptor.new secret
    end

    def encrypt data
      encryptor.encrypt_and_sign data
    end

    def decrypt data
      encryptor.decrypt_and_verify data
    end

    private

    attr_reader :encryptor
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
auther-12.2.0 lib/auther/cipher.rb
auther-12.1.0 lib/auther/cipher.rb
auther-12.0.3 lib/auther/cipher.rb
auther-12.0.2 lib/auther/cipher.rb
auther-12.0.1 lib/auther/cipher.rb
auther-12.0.0 lib/auther/cipher.rb
auther-11.5.0 lib/auther/cipher.rb
auther-11.4.0 lib/auther/cipher.rb
auther-11.3.0 lib/auther/cipher.rb
auther-11.2.0 lib/auther/cipher.rb
auther-11.1.0 lib/auther/cipher.rb
auther-11.0.1 lib/auther/cipher.rb
auther-11.0.0 lib/auther/cipher.rb
auther-10.2.3 lib/auther/cipher.rb
auther-10.2.2 lib/auther/cipher.rb
auther-10.2.1 lib/auther/cipher.rb
auther-10.2.0 lib/auther/cipher.rb
auther-10.1.0 lib/auther/cipher.rb
auther-10.0.0 lib/auther/cipher.rb
auther-9.3.0 lib/auther/cipher.rb