45 if ( self::$algo !==
null ) {
49 $algos = hash_algos();
50 $preference = [
'whirlpool',
'sha256',
'sha1',
'md5' ];
52 foreach ( $preference as $algorithm ) {
53 if ( in_array( $algorithm, $algos ) ) {
54 self::$algo = $algorithm;
65 throw new DomainException(
"Could not find an acceptable hashing function in hash_algos()" );
77 $key = $raw ?
'binary' :
'hex';
78 if ( self::$hashLength[$key] ===
null ) {
79 self::$hashLength[$key] = strlen( self::hash(
'', $raw ) );
82 return self::$hashLength[$key];
93 public static function hash( $data, $raw =
true ) {
94 return hash( self::hashAlgo(), $data, $raw );
106 public static function hmac( $data, $key, $raw =
true ) {
107 if ( !is_string( $key ) ) {
109 throw new InvalidArgumentException(
'Invalid key type: ' . gettype( $key ) );
111 return hash_hmac( self::hashAlgo(), $data, $key, $raw );
static $hashLength
The number of bytes outputted by the hash algorithm.
static hashAlgo()
Decide on the best acceptable hash algorithm we have available for hash()
static hashLength( $raw=true)
Return the byte-length output of the hash algorithm we are using in self::hash and self::hmac.
static $algo
The hash algorithm being used.
static hmac( $data, $key, $raw=true)
Generate an acceptably unstable one-way-hmac of some text making use of the best hash algorithm that ...
static hash( $data, $raw=true)
Generate an acceptably unstable one-way-hash of some text making use of the best hash algorithm that ...