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
19 20 21 |
# File 'lib/lite/encryption/key.rb', line 19 def generate_iv SecureRandom.random_bytes(LENGTHS[:iv]) end |
.generate_key ⇒ Object
23 24 25 26 |
# File 'lib/lite/encryption/key.rb', line 23 def generate_key generator = ActiveSupport::KeyGenerator.new(generate_password) generator.generate_key(generate_salt, LENGTHS[:key]) end |
.generate_password ⇒ Object
28 29 30 |
# File 'lib/lite/encryption/key.rb', line 28 def generate_password SecureRandom.hex(LENGTHS[:password]) end |
.generate_salt ⇒ Object
32 33 34 |
# File 'lib/lite/encryption/key.rb', line 32 def generate_salt SecureRandom.random_bytes(LENGTHS[:salt]) end |