Inheritance: extends PublicKey
Example #1
0
 /**
  * Verify a signed message with the correct public key
  * 
  * @param string $message Message to verify
  * @param SignaturePublicKey $publicKey
  * @param string $signature
  * @param boolean $raw Don't hex decode the input?
  * @return bool
  * @throws CryptoException\InvalidSignature
  */
 public static function verify(string $message, SignaturePublicKey $publicKey, string $signature, bool $raw = false) : bool
 {
     if (!$raw) {
         $signature = \Sodium\hex2bin($signature);
     }
     if (CryptoUtil::safeStrlen($signature) !== \Sodium\CRYPTO_SIGN_BYTES) {
         throw new CryptoException\InvalidSignature('Signature is not the correct length; is it encoded?');
     }
     return \Sodium\crypto_sign_verify_detached($signature, $message, $publicKey->getRawKeyMaterial());
 }