Class: Lockbox::KeyGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/lockbox/key_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(master_key) ⇒ KeyGenerator

Returns a new instance of KeyGenerator.



3
4
5
# File 'lib/lockbox/key_generator.rb', line 3

def initialize(master_key)
  @master_key = master_key
end

Instance Method Details

#attribute_key(table:, attribute:) ⇒ Object

pattern ported from CipherSweet ciphersweet.paragonie.com/internals/key-hierarchy

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
# File 'lib/lockbox/key_generator.rb', line 9

def attribute_key(table:, attribute:)
  raise ArgumentError, "Missing table for key generation" if table.to_s.empty?
  raise ArgumentError, "Missing attribute for key generation" if attribute.to_s.empty?

  c = "\xB4"*32
  hkdf(Lockbox::Utils.decode_key(@master_key, name: "Master key"), salt: table.to_s, info: "#{c}#{attribute}", length: 32, hash: "sha384")
end