Example #1
0
 /**
  * Verify the authenticity of a message, given a shared MAC key
  * 
  * @param string $message
  * @param AuthenticationKey $secretKey
  * @param string $mac
  * @param mixed $encoding
  * @param SymmetricConfig $config
  * @return bool
  */
 public static function verify(string $message, AuthenticationKey $secretKey, string $mac, $encoding = Halite::ENCODE_BASE64URLSAFE, SymmetricConfig $config = null) : bool
 {
     $decoder = Halite::chooseEncoder($encoding, true);
     if ($decoder) {
         // We were given hex data:
         $mac = $decoder($mac);
     }
     if ($config === null) {
         // Default to the current version
         $config = SymmetricConfig::getConfig(Halite::HALITE_VERSION, 'auth');
     }
     return self::verifyMAC($mac, $message, $secretKey->getRawKeyMaterial(), $config);
 }
Example #2
0
 /**
  * Authenticate a message
  * 
  * @param string|resource $plaintext
  * @param AuthenticationKey $key
  * @return string
  */
 public function authSymmetric($plaintext, AuthenticationKey $key, array $options = []) : string
 {
     return \hash_hmac($this->config['hash'], $plaintext, $key->getRawBytes(), true);
 }
Example #3
0
 /**
  * Verify a MAC, given a MAC key
  * 
  * @param string $message
  * @param AuthenticationKey $secretKey
  * @param string $mac
  * @param boolean $raw
  * @return boolean
  */
 public static function verify(string $message, AuthenticationKey $secretKey, string $mac, bool $raw = false) : bool
 {
     if (!$raw) {
         $mac = \Sodium\hex2bin($mac);
     }
     return self::verifyMAC($mac, $message, $secretKey->getRawKeyMaterial());
 }