Class: Reth::Keystore::PBKDF2

Inherits:
Object
  • Object
show all
Defined in:
lib/reth/keystore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = nil) ⇒ PBKDF2

Returns a new instance of PBKDF2.



12
13
14
15
# File 'lib/reth/keystore.rb', line 12

def initialize(params=nil)
  @name = 'pbkdf2'
  @params = params || mkparams
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/reth/keystore.rb', line 10

def name
  @name
end

Instance Method Details

#eval(pw) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/reth/keystore.rb', line 17

def eval(pw)
  OpenSSL::PKCS5.pbkdf2_hmac(
    pw,
    Utils.decode_hex(params[:salt]),
    params[:c],
    params[:dklen],
    'SHA256'
  )
end

#mkparamsObject



27
28
29
30
31
32
# File 'lib/reth/keystore.rb', line 27

def mkparams
  { prf: 'hmac-sha256',
    dklen: 32,
    c: 262144,
    salt: Utils.encode_hex(SecureRandom.random_bytes(16)) }
end