Dcrypt\Hash::ihmac PHP Method

ihmac() public static method

This class always performs at least one hash to prevent the input from being passed back unchanged if bad parameters are set.
public static ihmac ( string $data, string $key, integer $iter, string $algo = 'sha256' ) : string
$data string Data to hash.
$key string Key to use to authenticate the hash.
$iter integer Number of times to iteratate the hash
$algo string Name of algo (sha256 or sha512 recommended)
return string
    public static function ihmac($data, $key, $iter, $algo = 'sha256')
    {
        $iter = abs($iter);
        for ($i = 0; $i <= $iter; $i++) {
            $data = \hash_hmac($algo, $data . $i . $iter, $key, true);
        }
        return $data;
    }

Usage Example

Beispiel #1
0
 public function testIhmacSanity()
 {
     // Make sure at least one hash always happens with any kind of crazy cost value
     $this->assertNotEquals('aaaa', Hash::ihmac('aaaa', 'bbbb', 0));
     $this->assertNotEquals('aaaa', Hash::ihmac('aaaa', 'bbbb', -1));
 }