Class: Auther::Cipher

Inherits:
Object
  • Object
show all
Defined in:
lib/auther/cipher.rb

Overview

Manages encryption/decryption.

Constant Summary collapse

BYTE_DIVISOR =
2

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret) ⇒ Cipher

Returns a new instance of Cipher.



17
18
19
# File 'lib/auther/cipher.rb', line 17

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

Class Method Details

.generate(login, password) ⇒ Object



8
9
10
11
12
13
# File 'lib/auther/cipher.rb', line 8

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

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

.key_lengthObject



15
# File 'lib/auther/cipher.rb', line 15

def self.key_length = ActiveSupport::MessageEncryptor.key_len

Instance Method Details

#decrypt(data) ⇒ Object



23
# File 'lib/auther/cipher.rb', line 23

def decrypt(data) = encryptor.decrypt_and_verify data

#encrypt(data) ⇒ Object



21
# File 'lib/auther/cipher.rb', line 21

def encrypt(data) = encryptor.encrypt_and_sign data