PHP Class PHPDaemon\Utils\Crypt

Author: Vasily Zorin ([email protected])
Inheritance: use trait PHPDaemon\Traits\ClassWatchdog
Show file Open project: kakserpom/phpdaemon Class Usage Examples

Public Methods

Method Description
compareStrings ( string $a, string $b ) : boolean Compare strings
hash ( string $str, string $salt = '', boolean $plain = false ) : string Generate keccak hash for string with salt
randomBytes ( integer $len, callable $cb, integer $pri, boolean $hang = false ) : integer Returns string of pseudo random bytes
randomInts ( integer $numInts, callable $cb, integer $pri, boolean $hang = false ) : integer Returns array of pseudo random integers of machine-dependent size
randomInts32 ( integer $numInts, callable $cb, integer $pri, boolean $hang = false ) : integer Returns array of pseudo random 32-bit integers
randomString ( integer $len = null, string $chars = null, callable $cb = null, integer $pri, boolean $hang = false ) : string Returns string of pseudo random characters
stringIdx ( string $str, integer $idx ) : string Returns the character at index $idx in $str in constant time

Protected Methods

Method Description
getMinimalBitMask ( integer $toRepresent ) : integer Returns the smallest bit mask of all 1s such that ($toRepresent & mask) = $toRepresent

Method Details

compareStrings() public static method

Compare strings
Deprecation:
public static compareStrings ( string $a, string $b ) : boolean
$a string String 1
$b string String 2
return boolean Equal?

getMinimalBitMask() protected static method

Returns the smallest bit mask of all 1s such that ($toRepresent & mask) = $toRepresent
protected static getMinimalBitMask ( integer $toRepresent ) : integer
$toRepresent integer must be an integer greater than or equal to 1
return integer

hash() public static method

Generate keccak hash for string with salt
Deprecation:
public static hash ( string $str, string $salt = '', boolean $plain = false ) : string
$str string Data
$salt string Salt
$plain boolean Is plain text?
return string

randomBytes() public static method

Returns string of pseudo random bytes
public static randomBytes ( integer $len, callable $cb, integer $pri, boolean $hang = false ) : integer
$len integer Length of desired string
$cb callable Callback
$pri integer Priority of EIO operation
$hang boolean If true, we shall use /dev/random instead of /dev/urandom and it may cause a delay
return integer

randomInts() public static method

Returns array of pseudo random integers of machine-dependent size
public static randomInts ( integer $numInts, callable $cb, integer $pri, boolean $hang = false ) : integer
$numInts integer Number of integers
$cb callable Callback
$pri integer Priority of EIO operation
$hang boolean If true, we shall use /dev/random instead of /dev/urandom and it may cause a delay
return integer

randomInts32() public static method

Returns array of pseudo random 32-bit integers
public static randomInts32 ( integer $numInts, callable $cb, integer $pri, boolean $hang = false ) : integer
$numInts integer Number of integers
$cb callable Callback
$pri integer Priority of EIO operation
$hang boolean If true, we shall use /dev/random instead of /dev/urandom and it may cause a delay
return integer

randomString() public static method

Returns string of pseudo random characters
public static randomString ( integer $len = null, string $chars = null, callable $cb = null, integer $pri, boolean $hang = false ) : string
$len integer Length of desired string
$chars string String of allowed characters
$cb callable Callback
$pri integer Priority of EIO operation
$hang boolean If true, we shall use /dev/random instead of /dev/urandom and it may cause a delay
return string

stringIdx() public static method

Returns the character at index $idx in $str in constant time
public static stringIdx ( string $str, integer $idx ) : string
$str string String
$idx integer Index
return string