class Auther::Cipher

Manages encryption/decryption.

Constants

BYTE_DIVISOR

Public Class Methods

generate(login, password) click to toggle source
# File lib/auther/cipher.rb, line 8
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
key_length(= ActiveSupport::MessageEncryptor.key_len) click to toggle source
# File lib/auther/cipher.rb, line 15
  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
new(secret) click to toggle source
# File lib/auther/cipher.rb, line 17
def initialize secret
  @encryptor = ActiveSupport::MessageEncryptor.new secret
end

Public Instance Methods

decrypt(data) click to toggle source
# File lib/auther/cipher.rb, line 23
  def decrypt(data) = encryptor.decrypt_and_verify data

  private

  attr_reader :encryptor
end
encrypt(data) click to toggle source
# File lib/auther/cipher.rb, line 21
    def encrypt(data) = encryptor.encrypt_and_sign data

    def decrypt(data) = encryptor.decrypt_and_verify data

    private

    attr_reader :encryptor
  end
end