PHP Class ElggCrypto, Elgg

Afficher le fichier Open project: elgg/elgg Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( SiteSecret $site_secret = null ) Constructor
areEqual ( string $str1, string $str2 ) : boolean Are two strings equal (compared in constant time)?
getHmac ( mixed $data, string $algo = 'sha256', string $key = '' ) : Elgg\Security\Hmac Get an HMAC token builder/validator object
getRandomBytes ( integer $length ) : string Generate a string of highly randomized bytes (over the full 8-bit range).
getRandomString ( integer $length, string | null $chars = null ) : string Generate a random string of specified length.

Méthodes protégées

Méthode Description
strlen ( string $binary_string ) : integer Count the number of bytes in a string

Method Details

__construct() public méthode

Constructor
public __construct ( SiteSecret $site_secret = null )
$site_secret Elgg\Database\SiteSecret Secret service

areEqual() public méthode

Are two strings equal (compared in constant time)?
Author: Anthony Ferrara ([email protected])
public areEqual ( string $str1, string $str2 ) : boolean
$str1 string First string to compare
$str2 string Second string to compare
Résultat boolean Based on password_verify in PasswordCompat

getHmac() public méthode

Get an HMAC token builder/validator object
public getHmac ( mixed $data, string $algo = 'sha256', string $key = '' ) : Elgg\Security\Hmac
$data mixed HMAC data or serializable data
$algo string Hash algorithm
$key string Optional key (default uses site secret)
Résultat Elgg\Security\Hmac

getRandomBytes() public méthode

Generate a string of highly randomized bytes (over the full 8-bit range).
public getRandomBytes ( integer $length ) : string
$length integer Number of bytes needed
Résultat string Random bytes

getRandomString() public méthode

Uses supplied character list for generating the new string. If no character list provided - uses Base64 URL character set.
See also: https://github.com/zendframework/zf2/blob/master/library/Zend/Math/Rand.php#L179
public getRandomString ( integer $length, string | null $chars = null ) : string
$length integer Desired length of the string
$chars string | null Characters to be chosen from randomly. If not given, the Base64 URL charset will be used.
Résultat string The random string

strlen() protected méthode

We cannot simply use strlen() for this, because it might be overwritten by the mbstring extension. In this case, strlen() will count the number of *characters* based on the internal encoding. A sequence of bytes might be regarded as a single multibyte character. Use elgg_strlen() to count UTF-characters instead of bytes.
Author: Anthony Ferrara ([email protected])
protected strlen ( string $binary_string ) : integer
$binary_string string The input string
Résultat integer The number of bytes From PasswordCompat\binary\_strlen