class Universa::PBKDF2
Utiliy to generate keys of arbitrary length derived from passwords using PBKDF2
algorithm. Use {derive} to produce keys from passwords in a realtively safe way (safety depends on the password strength)
Public Class Methods
derive(password, salt: "default_salt", rounds: 50000, hash: 'com.icodici.crypto.digest.Sha256', length: 32)
click to toggle source
Derive a binary key from the string password using PBKDF2
algorithm.
@param [String] password to derive key from @param [String] salt @param [Integer] rounds using in the PNKDF2 generation @param [String] hash class name, should include packgae name. See Universa
crypto Digest class @param [Integer] length of the derived key. @return [Binary] binary string with generated key
# 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