Class: RomEncryptedAttribute::KeyDerivator

Inherits:
Object
  • Object
show all
Defined in:
lib/rom_encrypted_attribute/key_derivator.rb

Constant Summary collapse

DEFAULT_DIGEST_CLASS =
OpenSSL::Digest::SHA1
ITERATIONS =
2**16

Instance Method Summary collapse

Constructor Details

#initialize(secret:, salt:, hash_digest_class: DEFAULT_DIGEST_CLASS) ⇒ KeyDerivator

Returns a new instance of KeyDerivator.



10
11
12
13
14
# File 'lib/rom_encrypted_attribute/key_derivator.rb', line 10

def initialize(secret:, salt:, hash_digest_class: DEFAULT_DIGEST_CLASS)
  @secret = secret
  @salt = salt
  @hash_digest_class = hash_digest_class
end

Instance Method Details

#derive(size) ⇒ Object



16
17
18
# File 'lib/rom_encrypted_attribute/key_derivator.rb', line 16

def derive(size)
  OpenSSL::PKCS5.pbkdf2_hmac(@secret, @salt, ITERATIONS, size, @hash_digest_class.new)
end