Sha256: 6557c21eaf20b6511f8f83acb733dac71ec955e2ec5a32324254345bbfd433ca

Contents?: true

Size: 695 Bytes

Versions: 17

Compression:

Stored size: 695 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:, 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

17 entries across 17 versions & 1 rubygems

Version Path
auther-15.0.2 lib/auther/cipher.rb
auther-15.0.1 lib/auther/cipher.rb
auther-15.0.0 lib/auther/cipher.rb
auther-14.0.3 lib/auther/cipher.rb
auther-14.0.2 lib/auther/cipher.rb
auther-14.0.1 lib/auther/cipher.rb
auther-14.0.0 lib/auther/cipher.rb
auther-13.6.0 lib/auther/cipher.rb
auther-13.5.0 lib/auther/cipher.rb
auther-13.4.0 lib/auther/cipher.rb
auther-13.3.0 lib/auther/cipher.rb
auther-13.2.3 lib/auther/cipher.rb
auther-13.2.2 lib/auther/cipher.rb
auther-13.2.1 lib/auther/cipher.rb
auther-13.2.0 lib/auther/cipher.rb
auther-13.1.0 lib/auther/cipher.rb
auther-13.0.0 lib/auther/cipher.rb