verify() public static méthode

Verify the authenticity of a message, given a shared MAC key
public static verify ( string $message, AuthenticationKey $secretKey, string $mac, mixed $encoding = Halite::ENCODE_BASE64URLSAFE, SymmetricConfig $config = null ) : boolean
$message string
$secretKey AuthenticationKey
$mac string
$encoding mixed
$config SymmetricConfig
Résultat boolean
Exemple #1
0
 /**
  * @covers Symmetric::authenticate()
  * @covers Symmetric::verify()
  */
 public function testAuthenticateFail()
 {
     $key = new AuthenticationKey(new HiddenString(\str_repeat('A', 32), true));
     $message = 'test message';
     $mac = Symmetric::authenticate($message, $key, true);
     // Test invalid message
     $this->assertFalse(Symmetric::verify('othermessage', $key, $mac, true));
     $r = \Sodium\randombytes_uniform(\mb_strlen($mac, '8bit'));
     $_mac = $mac;
     $_mac[$r] = \chr(\ord($_mac[$r]) ^ 1 << \Sodium\randombytes_uniform(8));
     // Test invalid signature
     $this->assertFalse(Symmetric::verify($message, $key, $_mac, true));
 }