RobRichards\XMLSecLibs\XMLSecurityKey::verifySignature PHP Method

verifySignature() public method

Verifies the data (string) against the given signature using the extension assigned to the type in the constructor.
public verifySignature ( string $data, string $signature ) : boolean | integer
$data string
$signature string
return boolean | integer
    public function verifySignature($data, $signature)
    {
        switch ($this->cryptParams['library']) {
            case 'openssl':
                return $this->verifyOpenSSL($data, $signature);
            case self::HMAC_SHA1:
                $expectedSignature = hash_hmac("sha1", $data, $this->key, true);
                return strcmp($signature, $expectedSignature) == 0;
        }
    }

Usage Example

Example #1
0
 /**
  * @param XMLSecurityKey $objKey
  * @return bool|int
  * @throws Exception
  */
 public function verify($objKey)
 {
     $doc = $this->sigNode->ownerDocument;
     $xpath = new DOMXPath($doc);
     $xpath->registerNamespace('secdsig', self::XMLDSIGNS);
     $query = "string(./secdsig:SignatureValue)";
     $sigValue = $xpath->evaluate($query, $this->sigNode);
     if (empty($sigValue)) {
         throw new Exception("Unable to locate SignatureValue");
     }
     return $objKey->verifySignature($this->signedInfo, base64_decode($sigValue));
 }