Class: ROM::EncryptedAttribute::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.



11
12
13
14
15
# File 'lib/rom/encrypted_attribute/key_derivator.rb', line 11

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



17
18
19
# File 'lib/rom/encrypted_attribute/key_derivator.rb', line 17

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