/*
@description
Verifies the signature for the message and
returns true if verification succeeded or false if it failed.
509384
public boolean detached_verify(byte [] message, byte [] signature) {
            if (signature.length != signatureLength)
                return false;
            if (theirPublicKey.length != publicKeyLength)
                return false;
            byte [] sm = new byte[signatureLength + message.length];
            byte [] m = new byte[signatureLength + message.length];
            for (int i = 0; i < signatureLength; i++)
                sm[i] = signature[i];
            for (int i = 0; i < message.length; i++)
                sm[i + signatureLength] = message[i];
            return (crypto_sign_open(m, -1, sm, 0, sm.length, theirPublicKey) >= 0);
        }
368900
public boolean validateSignature(@NonNull byte[] content, @NonNull String headerSignature) {
        final byte[] signature = generateSignature(content);
        final byte[] decodeHeaderSignature = Base64.getDecoder().decode(headerSignature);
        return MessageDigest.isEqual(decodeHeaderSignature, signature);
    }
282279
public static boolean verify(
      Signature signatureAlgorithm, PublicKey publicKey, byte[] signatureBytes, byte[] contentBytes)
      throws InvalidKeyException, SignatureException {
    signatureAlgorithm.initVerify(publicKey);
    signatureAlgorithm.update(contentBytes);
    // SignatureException may be thrown if we are tring the wrong key.
    try {
      return signatureAlgorithm.verify(signatureBytes);
    } catch (SignatureException e) {
      return false;
    }
  }
1099397
protected function verify()
    {
        # Firstly, we need to make sure that there's an association.
        # Otherwise the verification will fail, 
        # because we've signed assoc_handle in the assertion
        if(empty($this->assoc)) {
            return false;
        }
        
        # Next, we check that it's a private association, 
        # i.e. one made without RP input.
        # Otherwise, the RP shouldn't ask us to verify.
        if(empty($this->assoc['private'])) {
            return false;
        }
        
        # Now we have to check if the nonce is correct, to prevent replay attacks.
        if($this->data['openid_response_nonce'] != $this->assoc['nonce']) {
            return false;
        }
        
        # Getting the signed fields for signature.
        $sig = array();
        $signed = explode(',', $this->data['openid_signed']);
        foreach($signed as $field) {
            $name = strtr($field, '.', '_');
            if(!isset($this->data['openid_' . $name])) {
                return false;
            }
            
            $sig[$field] = $this->data['openid_' . $name];
        }
        
        # Computing the signature and checking if it matches.
        $sig = $this->keyValueForm($sig);
        if ($this->data['openid_sig'] != 
            base64_encode(hash_hmac($this->assoc['hash'], $sig, $this->assoc['mac'], true))
        ) {
            return false;
        }
        
        # Clearing the nonce, so that it won't be used again.
        $this->assoc['nonce'] = null;
        
        if(empty($this->assoc['private'])) {
            # Commiting changes to the association.
            $this->setAssoc($this->assoc['handle'], $this->assoc);
        } else {
            # Private associations shouldn't be used again, se we can as well delete them.
            $this->delAssoc($this->assoc['handle']);
        }
        
        # Nothing has failed, so the verification was a success.
        return true;
    }
775622
public boolean isSignatureValid() {
        try {
            return ECKey.verify(Sha256Hash.hashTwice(content), signature, params.getAlertSigningKey());
        } catch (SignatureDecodeException e) {
            return false;
        }
    }
1294400
function verify(publicKeys, sig, text) {
    // Parse signature.
    validateBase64(sig);
    const binsig = Buffer.from(sig, 'base64');

    // Check signature length.
    if (binsig.length !== 10 + nacl.sign.signatureLength) {
        throw new Error('Bad signature length');
    }

    // Check signature algorithm.
    if (binsig[0] !== 69 /* 'E' */ || binsig[1] !== 100 /* 'd' */) {
        throw new Error('Unknown signature algorithm');
    }

    // Find the appropriate key for signature based on
    // algorithm and public key fingerprint embedded into signature.
    let key = null;
    for (let i = 0; i < publicKeys.length; i++) {
        const binkey = Buffer.from(publicKeys[i], 'base64');

        // Check public  key format.
        if (binkey.length !== 10 + nacl.sign.publicKeyLength) {
            throw new Error('Bad public key length');
        }

        // If algorithm (2 bytes) and key number (8) bytes match,
        // we found the needed key.
        if (nacl.verify(binkey.subarray(0, 10), binsig.subarray(0, 10))) {
            key = binkey;
            break;
        }
    }
    if (!key) {
        throw new Error('Invalid signature: no matching key found');
    }

    const bintext = Buffer.from(text, 'utf8');
    if (!nacl.sign.detached.verify(bintext, binsig.subarray(10), key.subarray(10))) {
        throw new Error('Invalid signature');
    }
}
562035
public function checkSignature(string $signature, string $data, string $publicKey): bool
    {
        return $this->getJson([
            'q' => 'checkSignature',
            'signature' => $signature,
            'data' => $data,
            'public_key' => $publicKey,
        ]);
    }
757163
def verify_signature(message, signature, address):
    
    if (len(signature) != SIGNATURE_LENGTH):
        return False

    try:
        binsig = base64.b64decode(signature)
    except:
        return False

    r = intbytes.from_bytes(binsig[1:33])

    s = intbytes.from_bytes(binsig[33:65])

    val = intbytes.from_bytes(bitcoin_sig_hash(message.encode()))

    pubpairs = possible_public_pairs_for_signature(
        generator_secp256k1,
        val,
        (r, s))

    addr_hash160 = bitcoin_address_to_hash160_sec(address)

    for pair in pubpairs:
        if (public_pair_to_hash160_sec(pair, True) == addr_hash160):
            return True
        if (public_pair_to_hash160_sec(pair, False) == addr_hash160):
            return True

    return False
878388
private static void verifySignature(
      X509CertificateHolder cert,
      byte[] sig, byte[] data, AlgorithmIdentifier idf) throws CertificateException
  {
    try
    {
      String algorithm = SIGNATURE_OID_TO_STRING.get(idf.getAlgorithm());
      if (algorithm == null)
      {
        throw new NoSuchAlgorithmException(
            String.format("Unsupported signature OID. OID: %s", idf));
      }
      Signature signer = Signature.getInstance(
          algorithm, BouncyCastleProvider.PROVIDER_NAME);

      X509Certificate c = CONVERTER_X509.getCertificate(cert);
      signer.initVerify(c.getPublicKey());
      signer.update(data);
      if (!signer.verify(sig))
      {
        throw new CertificateEncodingException(
            String.format("Failed to verify the signature. Potentially the " +
                          "data was not generated by by the cert, %s", cert.getSubject()));
      }
    }
    catch (NoSuchAlgorithmException | NoSuchProviderException |
        InvalidKeyException | SignatureException ex)
    {
      throw new CertificateEncodingException(
          "Failed to verify the signature.", ex);
    }
  }
776027
def verify_message(address, message, signature):
    
    bitcoin_message = BitcoinMessage(message)
    verified = VerifyMessage(address, bitcoin_message, signature)
    return verified
145608
public boolean verify(byte[] data, byte[] sign, byte[] id) {
		lock.lock();
		final SM2Signer signer = getSigner();
		try {
			CipherParameters param = getCipherParameters(KeyType.PublicKey);
			if (id != null) {
				param = new ParametersWithID(param, id);
			}
			signer.init(false, param);
			signer.update(data, 0, data.length);
			return signer.verifySignature(sign);
		} catch (Exception e) {
			throw new CryptoException(e);
		} finally {
			lock.unlock();
		}
	}
833539
private boolean verifySignature(Signature signature, String providedSignature) {
        // We can only make one call to Signature#verify here.
        // Since we need to potentially check two values (one decoded from hex, the other decoded from base64),
        // try hex first: It's almost certainly going to fail decoding if a base64 string was passed.
        // It is extremely unlikely for base64 strings to be a valid hex string.
        // This way, if it's base64, the #verify call will be skipped, and we continue with the #verify for decoded base64.
        // This approach might look unnecessarily clever, but short of having redundant Signature instances,
        // there doesn't seem to be a better approach for this.
        try {
            if (signature.verify(Hex.decodeHex(providedSignature.toCharArray()))) {
                return true;
            }
        } catch (SignatureException|DecoderException ignore) {
            // ignore
        }

        try {
            if (signature.verify(Base64.getDecoder().decode(providedSignature))) {
                return true;
            }
        } catch (SignatureException|IllegalArgumentException ignore) {
            // ignore
        }
        return false;
    }
546840
function verify($data, $signature) {
    $status = openssl_verify($data, $signature, $this->publicKey, "sha256");
    if ($status === -1) {
      throw new Exception('Signature verification error: ' . openssl_error_string());
    }
    return $status === 1;
  }
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);
}
104147
private function checkSignature() 
    {
        if ($this->signature !== false && $this->timestamp !== false && $this->nonce !== false) {
            $tmp_signature = SHA1::getSignature($this->token, $this->timestamp, $this->nonce);
            if ($tmp_signature === false) {
                error_log('Validate signature error.', 0);
            } else if ($tmp_signature === $this->signature) {
                return true;
            }
        }
        return false;
    }
10394
public static boolean isSelfSigned(X509Certificate cert,
        String sigProvider) {
        if (isSelfIssued(cert)) {
            try {
                if (sigProvider == null) {
                    cert.verify(cert.getPublicKey());
                } else {
                    cert.verify(cert.getPublicKey(), sigProvider);
                }
                return true;
            } catch (Exception e) {
                // In case of exception, return false
            }
        }
        return false;
    }
880988
function signSPKAC($signatureAlgorithm = 'sha1WithRSAEncryption')
    {
        if (!is_object($this->privateKey)) {
            return false;
        }

        $origPublicKey = $this->publicKey;
        $class = get_class($this->privateKey);
        $this->publicKey = new $class();
        $this->publicKey->loadKey($this->privateKey->getPublicKey());
        $this->publicKey->setPublicKey();
        $publicKey = $this->_formatSubjectPublicKey();
        if (!$publicKey) {
            return false;
        }
        $this->publicKey = $origPublicKey;

        $currentCert = isset($this->currentCert) ? $this->currentCert : null;
        $signatureSubject = isset($this->signatureSubject) ? $this->signatureSubject: null;

        // re-signing a SPKAC seems silly but since everything else supports re-signing why not?
        if (isset($this->currentCert) && is_array($this->currentCert) && isset($this->currentCert['publicKeyAndChallenge'])) {
            $this->currentCert['signatureAlgorithm']['algorithm'] = $signatureAlgorithm;
            $this->currentCert['publicKeyAndChallenge']['spki'] = $publicKey;
            if (!empty($this->challenge)) {
                // the bitwise AND ensures that the output is a valid IA5String
                $this->currentCert['publicKeyAndChallenge']['challenge'] = $this->challenge & str_repeat("\x7F", strlen($this->challenge));
            }
        } else {
            $this->currentCert = array(
                'publicKeyAndChallenge' =>
                    array(
                        'spki' => $publicKey,
                        // quoting <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen>,
                        // "A challenge string that is submitted along with the public key. Defaults to an empty string if not specified."
                        // both Firefox and OpenSSL ("openssl spkac -key private.key") behave this way
                        // we could alternatively do this instead if we ignored the specs:
                        // Random::string(8) & str_repeat("\x7F", 8)
                        'challenge' => !empty($this->challenge) ? $this->challenge : ''
                    ),
                    'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm),
                    'signature'          => false // this is going to be overwritten later
            );
        }

        // resync $this->signatureSubject
        // save $publicKeyAndChallenge in case there are any \phpseclib\File\ASN1\Element objects in it
        $publicKeyAndChallenge = $this->currentCert['publicKeyAndChallenge'];
        $this->loadSPKAC($this->saveSPKAC($this->currentCert));

        $result = $this->_sign($this->privateKey, $signatureAlgorithm);
        $result['publicKeyAndChallenge'] = $publicKeyAndChallenge;

        $this->currentCert = $currentCert;
        $this->signatureSubject = $signatureSubject;

        return $result;
    }