Class: Auther::Cipher
- Inherits:
-
Object
- Object
- Auther::Cipher
- Defined in:
- lib/auther/cipher.rb
Overview
Manages encryption/decryption.
Constant Summary collapse
- BYTE_DIVISOR =
2
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt(data) ⇒ Object
- #encrypt(data) ⇒ Object
-
#initialize(secret) ⇒ Cipher
constructor
A new instance of Cipher.
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 login, password secret = SecureRandom.hex key_length / BYTE_DIVISOR cipher = new secret {secret:, login: cipher.encrypt(login), password: cipher.encrypt(password)} end |
.key_length ⇒ Object
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 |