Sha256: b8f25ca956170197bf55863cc24ecb5b9aa7c1bbe5346722c0ed742993336c24

Contents?: true

Size: 515 Bytes

Versions: 2

Compression:

Stored size: 515 Bytes

Contents

# frozen_string_literal: true

require "openssl"

module ROM
  module EncryptedAttribute
    class KeyDerivator
      DEFAULT_DIGEST_CLASS = OpenSSL::Digest::SHA1
      ITERATIONS = 2**16

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-encrypted_attribute-0.0.4 lib/rom/encrypted_attribute/key_derivator.rb
rom-encrypted_attribute-0.0.3 lib/rom/encrypted_attribute/key_derivator.rb