Validate a signed message

@param SamlMessage|Assertion $message
@param XMLSecurityKey        $key

@return bool

@throws SamlException|SecurityException
194019
public function validateSignature($message, XMLSecurityKey $key)
    {
        $reader = $message->getSignature();
        if ($reader instanceof AbstractSignatureReader) {
            try {
                return $reader->validate($key);
            } catch (\Exception $e) {
                throw new SamlException('urn:oasis:names:tc:SAML:2.0:status:RequestDenied', $e);
            }
        } else {
            throw new SecurityException('Saml message signature is not specified');
        }
    }
503725
protected function setMessageFormCheckout($key, $message)
    {
        gplcart_array_set($this->data_form['messages'], $key, $this->format($message));
    }
164031
function sign($message)
    {
        if (empty($this->modulus) || empty($this->exponent)) {
            return false;
        }

        switch ($this->signatureMode) {
            case self::SIGNATURE_PKCS1:
                return $this->_rsassa_pkcs1_v1_5_sign($message);
            //case self::SIGNATURE_PSS:
            default:
                return $this->_rsassa_pss_sign($message);
        }
    }
755051
public static function signWithPKCS15(RSAKey $key, string $message, string $hash): string
    {
        $em = self::encodeEMSA15($message, $key->getModulusLength(), Hash::$hash());
        $message = BigInteger::createFromBinaryString($em);
        $signature = RSAKey::exponentiate($key, $message);

        return self::convertIntegerToOctetString($signature, $key->getModulusLength());
    }
667210
public static function verifyWebhookSignature($signature, $message, $secretKey)
    {
        $data = "";

        if (is_string($message)) {
            $data = $message;
        } else {
            $data = json_encode($message);
        }
        return hash_hmac("sha256", $data, $secretKey) == $signature;
    }
873595
public static function validate_sig($token, $key)
    {
        try {
            \Firebase\JWT\JWT::decode($token, $key, array('HS256', 'HS384', 'HS512', 'RS256'));
            return true;
        } catch (\Exception $e) {
            return false;
        }
    }
758462
public function validateType($key, $type, $msg = '') {
        $this->obligate($key);
        $val = $this[$key];
        $msg = $msg ?: sprintf(self::EXCEPTION_INCORRECTTYPE, $key);
        $valid = true;
        if ($type === self::TYPE_ARRAY) {
            $valid = is_array($val);
        } elseif ($type === self::TYPE_OBJECT) {
            $valid = is_object($val);
        } elseif ($type === self::TYPE_NUMBER) {
            $valid = is_int($val) || is_float($val);
        } elseif ($type === self::TYPE_NUMERIC) {
            $valid = is_numeric($val);
        } elseif ($type === self::TYPE_STRING) {
            $valid = is_string($val);
        }

        if (!$valid) {
            throw new Garp_Util_Configuration_Exception_IncorrectType($msg);
        }
        return $this;
    }
473969
public function validateSign($secret)
	{

		$inputData = $this->input->all();
		Secure::sign($inputData, $this->sid(), $secret);
		if ($inputData['sign'] !== $this->input->sign) {
			throw new ProcessorException(ProcessorException::INVALID_SIGN);
		}

	}
643390
public static function sign($message, PrivateKey $rsaPrivateKey)
    {
        $rsa = self::getRsa(RSA::SIGNATURE_PSS);

        $return = $rsa->loadKey($rsaPrivateKey->getKey());
        if ($return === false) {
            throw new InvalidKeyException('Signing failed due to invalid key');
        }

        return $rsa->sign($message);
    }
790518
public function verify($expected, $payload, $key)
    {
        if (!$key instanceof Key) {
            $key = new Key($key);
        }
        $publicKey = $this->keyParser->parsePublicKey($key->getContent());

        $signature = $this->serializer->unserialize($expected, $this->config->getSignatureLength());

        $hash = $this->hash($payload);

        $signer = new EccSigner($this->adapter);

        return $signer->verify($publicKey, $signature, $hash);
    }
1092795
protected function validateKey()
    {
        if (\is_string($key = $this->key)) {
            if (\substr($key, 0, 7) !== 'file://') {
                $key = 'file://' . $key;
            }

            $this->key = \openssl_get_privatekey($key, $this->passphrase ?: '');
        }

        if (!\is_resource($this->key)) {
            throw new JWTException('Invalid key: Should be resource of private key', static::ERROR_KEY_INVALID);
        }
    }
1271273
public function encryptNameId(XMLSecurityKey $key) : void
    {
        if ($this->nameId === null) {
            throw new \Exception('Cannot encrypt NameID, no NameID set.');
        }
        /* First create an XML representation of the NameID. */
        $doc = DOMDocumentFactory::create();
        $root = $doc->createElement('root');
        $doc->appendChild($root);
        $this->nameId->toXML($root);
        /** @var \DOMElement $nameId */
        $nameId = $root->firstChild;

        Utils::getContainer()->debugMessage($nameId, 'encrypt');

        /* Encrypt the NameID. */
        $enc = new XMLSecEnc();
        $enc->setNode($nameId);
        // @codingStandardsIgnoreStart
        $enc->type = XMLSecEnc::Element;
        // @codingStandardsIgnoreEnd

        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
        $symmetricKey->generateSessionKey();
        $enc->encryptKey($key, $symmetricKey);

        /**
         * @var \DOMElement encryptedNameId
         * @psalm-suppress UndefinedClass
         */
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
        $this->nameId = null;
    }
1195574
public function verify($expected, $payload, $key)
    {
        return $this->signer->verify($expected, $payload, $key);
    }
950827
public static function assertXMLValid($XML, string $message = '')
    {
        AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertXMLValid', ['assertThat']);
        self::assertThat($XML, new XMLValidConstraint(), $message);
    }
1243026
private function validateKey($key)
    {
        $details = openssl_pkey_get_details($key);

        if (!isset($details['key']) || $details['type'] !== OPENSSL_KEYTYPE_RSA) {
            throw new \InvalidArgumentException('This key is not compatible with RSA signatures');
        }
    }
138710
public static function verifyMessageSignature($secret, $body = null, $signature = null) {

		// Compute hash of message using shared secret:
		$body = is_null($body) ? file_get_contents('php://input') : $body;
		$hash = base64_encode(hash_hmac('sha256', $body, $secret, true));

		// Compare hash to the signature:
		$signature = is_null($signature) ? $_SERVER['HTTP_X_ACUITY_SIGNATURE'] : $signature;
		if ($hash !== $signature) {
			throw new Exception('This message was forged!');
		}
	}
861384
function verify($message, $signature)
    {
        if (empty($this->modulus) || empty($this->exponent)) {
            return false;
        }

        switch ($this->signatureMode) {
            case self::SIGNATURE_PKCS1:
                return $this->_rsassa_pkcs1_v1_5_verify($message, $signature);
            //case self::SIGNATURE_PSS:
            default:
                return $this->_rsassa_pss_verify($message, $signature);
        }
    }