45 if ( !is_null( self::$algo ) ) {
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()" );
78 if ( is_null( self::$hashLength[$raw] ) ) {
79 self::$hashLength[$raw] = strlen( self::hash(
'', $raw ) );
82 return self::$hashLength[$raw];
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 );