Class: Universa::PBKDF2

Inherits:
RemoteAdapter show all
Defined in:
lib/universa/contract.rb

Overview

Utiliy to generate keys of arbitrary length derived from passwords using PBKDF2 algorithm. Use PBKDF2.derive to produce keys from passwords in a realtively safe way (safety depends on the password strength)

Class Method Summary collapse

Methods inherited from RemoteAdapter

#__getobj__, #__setobj__, #initialize, #inspect, invoke_static, remote_class, remote_class_name, remote_field, static_method, #to_s

Constructor Details

This class inherits a constructor from Universa::RemoteAdapter

Class Method Details

.derive(password, salt: "default_salt", rounds: 50000, hash: 'com.icodici.crypto.digest.Sha256', length: 32) ⇒ Binary

Derive a binary key from the string password using PBKDF2 algorithm.

Parameters:

  • password (String)

    to derive key from

  • salt (String) (defaults to: "default_salt")
  • rounds (Integer) (defaults to: 50000)

    using in the PNKDF2 generation

  • hash (String) (defaults to: 'com.icodici.crypto.digest.Sha256')

    class name, should include packgae name. See Universa crypto Digest class

  • length (Integer) (defaults to: 32)

    of the derived key.

Returns:

  • (Binary)

    binary string with generated key



32
33
34
35
# File 'lib/universa/contract.rb', line 32

def self.derive(password, salt: "default_salt", rounds: 50000, hash: 'com.icodici.crypto.digest.Sha256', length: 32)
  salt = salt.force_encoding('binary') if salt && salt.is_a?(String)
  invoke_static :derive, hash, password, salt, rounds, length
end