verifies if the given data is valid for the given signature and public key.

@throws SignatureException if the algorithm cannot be initialized
351114
public static boolean verify(byte[] text, byte[] signatureValue, PublicKey key, String algorithm)
        throws SignatureException {
        Signature signature;
        try {
            signature = Signature.getInstance(algorithm);
            signature.initVerify(key);
        } catch (GeneralSecurityException e) {
            throw new IllegalArgumentException("cannot initialize signature for algorithm " + algorithm, e);
        }
        signature.update(text);
        return signature.verify(signatureValue);
    }
1007386
private function verify($data, $signature, $publicKey)
    {
        $res = openssl_get_publickey($publicKey);
        $result = (bool) openssl_verify($data, base64_decode($signature), $res);
        openssl_free_key($res);

        return $result;
    }
1234320
protected function validateSignature()
    {
        $check = [];
        foreach ($this->data as $key => $value) {
            if ($key !== 'brq_signature') {
                $check[$key] = $value;
            }
        }

        $signature = new Signature($check, $this->secretKey);
        if (empty($this->data['brq_signature']) || (string)$signature !== $this->data['brq_signature']) {
            throw new InvalidSignatureException;
        }
    }
744036
private static boolean verifySignature(String content, String signed, RSAPublicKey pk) throws InvalidTokenException {
        try {
            byte[] signedData = Base64.urlDecode(signed);
            byte[] contentData = content.getBytes(JWT.UTF_8);

            Signature signature = Signature.getInstance(ALG_SHA256WITHRSA);
            signature.initVerify(pk);
            signature.update(contentData);

            return signature.verify(signedData);
        }catch (SignatureException e) {
            throw new InvalidTokenException("Invalid signature", e);
        }catch (Exception e) {
            throw new RuntimeException("Verify signature error", e);
        }
    }
573745
function verify(public_key, data, signature) {
  var pubkey = bitcoinjs.ECPubKey.fromHex(public_key);
  var hash = bitcoinjs.crypto.hash256(new Buffer(data, 'hex'));
  var ecsignature = bitcoinjs.ECSignature.fromDER(new Buffer(signature, 'hex'));
  return pubkey.verify(hash, ecsignature);
}
1108595
public boolean isValidSignature(final Key key) {
        final byte[] computedHmac = key.sign(getVersion(), getTimestamp(), getInitializationVector(),
                getCipherText());
        return Arrays.equals(getHmac(), computedHmac);
    }
269940
public function verify($signature, $identifier, &$initTime, &$expireTime, &$errorMsg)
    {
        try {
            $errorMsg = '';
            $decodedSig = $this->base64Decode($signature);
            $uncompressedSig = gzuncompress($decodedSig);
            if ($uncompressedSig === false) {
                throw new SignatureException('gzuncompress error');
            }
            $json = json_decode($uncompressedSig, true);
            if ($json == false) {
                throw new SignatureException('json_decode error');
            }
            $json = (array)$json;
            if ($json['TLS.identifier'] !== $identifier) {
                throw new SignatureException("identifier error sigid:{$json['TLS.identifier']} id:{$identifier}");
            }
            if ($json['TLS.sdk_appid'] != $this->appId) {
                throw new SignatureException("appid error sigappid:{$json['TLS.appid']} thisappid:{$this->appId}");
            }
            $content = $this->genSignatureContent($json);
            $signature = base64_decode($json['TLS.sig']);
            if ($signature == false) {
                throw new SignatureException('sig json_decode error');
            }
            $succ = $this->verifySignature($content, $signature);
            if (!$succ) {
                throw new SignatureException('verify failed');
            }
            $initTime = $json['TLS.time'];
            $expireTime = $json['TLS.expire_after'];
            return true;
        } catch (SignatureException $ex) {
            $errorMsg = $ex->getMessage();
            return false;
        }
    }
651237
protected function _checkSignatureAlgoAndKey(
        SignatureAlgorithmIdentifier $sig_algo, AlgorithmIdentifier $key_algo)
    {
        if (!$sig_algo->supportsKeyAlgorithm($key_algo)) {
            throw new \UnexpectedValueException(
                sprintf(
                    'Signature algorithm %s does not support key algorithm %s.',
                    $sig_algo->name(), $key_algo->name()));
        }
    }
208182
private boolean tryCreateSignatureVerifier() {
        long t = System.currentTimeMillis();
        if (t - lastKeyFetchTimestamp < oAuth2Properties.getSignatureVerification().getPublicKeyRefreshRateLimit()) {
            return false;
        }
        try {
            SignatureVerifier verifier = signatureVerifierClient.getSignatureVerifier();
            if (verifier != null) {
                setVerifier(verifier);
                lastKeyFetchTimestamp = t;
                log.debug("Public key retrieved from OAuth2 server to create SignatureVerifier");
                return true;
            }
        } catch (Throwable ex) {
            log.error("could not get public key from OAuth2 server to create SignatureVerifier", ex);
        }
        return false;
    }
726146
public static SignatureUtil buildInstance(String privateKey, String publicKey,
                                              Algorithms algorithms) {
        return new SignatureUtilImpl(privateKey, publicKey, algorithms);
    }
77884
protected String signAndBase64Encode(byte[] data, String key,
            SigningAlgorithm algorithm) throws SdkClientException {
        try {
            byte[] signature = sign(data, key.getBytes(UTF8), algorithm);
            return Base64.encodeAsString(signature);
        } catch (Exception e) {
            throw new SdkClientException(
                    "Unable to calculate a request signature: "
                            + e.getMessage(), e);
        }
    }
1103107
@Override
    public void init(boolean forward) throws CertPathValidatorException {
        if (!forward) {
            prevPubKey = trustedPubKey;
            if (PKIX.isDSAPublicKeyWithoutParams(prevPubKey)) {
                // If TrustAnchor is a DSA public key and it has no params, it
                // cannot be used to verify the signature of the first cert,
                // so throw exception
                throw new CertPathValidatorException("Key parameters missing");
            }
            prevSubject = caName;
        } else {
            throw new
                CertPathValidatorException("forward checking not supported");
        }
    }
1234414
public static function verifySignature($message, $signature, $signatureKey, $algorithm = 'MD5')
    {
        if (isset($signature)) {
            if ($algorithm === 'MD5') {
                $hash = md5($message . $signatureKey);
            } else if (in_array($algorithm, array('SHA', 'SHA1', 'SHA-1'))) {
                $hash = sha1($message . $signatureKey);
            } else {
                $hash = hash('sha256', $message . $signatureKey);
            }

            if (strcmp($signature, $hash) == 0) {
                return true;
            }
        }

        return false;
    }
1233995
public boolean verify() throws SignatureException {
        if (verified)
            return verifyResult;
        if (sigAttr != null) {
            sig.update(sigAttr);
            if (RSAdata != null) {
                byte msd[] = messageDigest.digest();
                messageDigest.update(msd);
            }
            verifyResult = (Arrays.equals(messageDigest.digest(), digestAttr) && sig.verify(digest));
        }
        else {
            if (RSAdata != null)
                sig.update(messageDigest.digest());
            verifyResult = sig.verify(digest);
        }
        verified = true;
        return verifyResult;
    }
27189
@Override
    public Builder signWith(String algorithm, Key key) throws KeyException {

        if (algorithm == null || algorithm.isEmpty() || !algorithm.equals(Constants.SIGNATURE_ALG_RS256)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_ALGORITHM_ERR", new Object[] { algorithm, Constants.SIGNATURE_ALG_RS256 });
            throw new KeyException(err);
        }
        if (key == null || !(key instanceof RSAPrivateKey)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_KEY_ERR", new Object[] { algorithm, key });
            throw new KeyException(err);
        }
        alg = algorithm;
        privateKey = key;
        return this;
    }
151447
static String sign(String data, String key, String algorithm) {
        try {
            Mac mac = Mac.getInstance(algorithm);
            mac.init(new SecretKeySpec(key.getBytes(DEFAULT_ENCODING), algorithm));
            byte[] signature = Base64.encodeBase64(mac.doFinal(data.getBytes(DEFAULT_ENCODING)));
            String encoded = new String(signature, DEFAULT_ENCODING);
            //log.debug("\nSign:"+data+"\nKey:"+key+"\nAlgorithm:"+algorithm+"\nSignature:"+encoded);
            return encoded;
        } catch (Exception e) {
            throw MwsUtl.wrap(e);
        }
    }
272547
public boolean verify(String message, String signature) {
		try {
			return verifier.verify(message.getBytes(charsetName), Base64.decodeBase64(signature));
		} catch (UnsupportedEncodingException e) {
			throw new SignatureException("unsupported encoding: charsetName=" + charsetName, e);
		} catch (Exception e) {
			return false;
		}
	}