Thruway\Common\Utils::getDerivedKey PHP Method

getDerivedKey() public static method

Encode and get derived key
public static getDerivedKey ( string $key, string $salt, integer $iterations = 1000, integer $keyLen = 32 ) : string
$key string
$salt string
$iterations integer
$keyLen integer
return string
    public static function getDerivedKey($key, $salt, $iterations = 1000, $keyLen = 32)
    {
        if (function_exists("hash_pbkdf2")) {
            $key = hash_pbkdf2('sha256', $key, $salt, $iterations, $keyLen, true);
        } else {
            // PHP v5.4 compatibility
            $key = static::compat_pbkdf2('sha256', $key, $salt, $iterations, $keyLen, true);
        }
        return base64_encode($key);
    }

Usage Example

示例#1
0
 /**
  * Add new user
  * 
  * @param string $userName
  * @param string $password
  * @param string $salt
  */
 function add($userName, $password, $salt = null)
 {
     if ($salt !== null) {
         $key = \Thruway\Common\Utils::getDerivedKey($password, $salt);
     } else {
         $key = $password;
     }
     $this->users[$userName] = ["authid" => $userName, "key" => $key, "salt" => $salt];
 }
All Usage Examples Of Thruway\Common\Utils::getDerivedKey