Sha256: 379fef1f020a794ebf7922ef89131afc6e52d660d4cb1e729937e79e14582789

Contents?: true

Size: 661 Bytes

Versions: 12

Compression:

Stored size: 661 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

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

    def encrypt(data) = encryptor.encrypt_and_sign data

    def decrypt(data) = encryptor.decrypt_and_verify data

    private

    attr_reader :encryptor
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
auther-17.0.0 lib/auther/cipher.rb
auther-16.10.0 lib/auther/cipher.rb
auther-16.9.0 lib/auther/cipher.rb
auther-16.8.0 lib/auther/cipher.rb
auther-16.7.0 lib/auther/cipher.rb
auther-16.6.0 lib/auther/cipher.rb
auther-16.5.0 lib/auther/cipher.rb
auther-16.4.0 lib/auther/cipher.rb
auther-16.3.0 lib/auther/cipher.rb
auther-16.2.0 lib/auther/cipher.rb
auther-16.1.0 lib/auther/cipher.rb
auther-16.0.0 lib/auther/cipher.rb