Class: Lite::Encryption::Key
- Inherits:
-
Object
- Object
- Lite::Encryption::Key
- Defined in:
- lib/lite/encryption/key.rb
Constant Summary collapse
- CIPHER =
OpenSSL::Cipher.new('aes-256-gcm').freeze
- LENGTHS =
{ iv: CIPHER.iv_len, key: CIPHER.key_len, password: 16, salt: CIPHER.key_len }.freeze
Class Method Summary collapse
Class Method Details
.generate_iv ⇒ Object
20 21 22 |
# File 'lib/lite/encryption/key.rb', line 20 def generate_iv SecureRandom.random_bytes(LENGTHS[:iv]) end |
.generate_key ⇒ Object
24 25 26 27 |
# File 'lib/lite/encryption/key.rb', line 24 def generate_key generator = ActiveSupport::KeyGenerator.new(generate_password) generator.generate_key(generate_salt, LENGTHS[:key]) end |
.generate_password ⇒ Object
29 30 31 |
# File 'lib/lite/encryption/key.rb', line 29 def generate_password SecureRandom.hex(LENGTHS[:password]) end |
.generate_salt ⇒ Object
33 34 35 |
# File 'lib/lite/encryption/key.rb', line 33 def generate_salt SecureRandom.random_bytes(LENGTHS[:salt]) end |