Verify signature

@param {Object} pk The public key
@param {Object} challenge The challenge
@param {Object} signature The signed challenge
@api private
495435
function(pk, challenge, signature) {
    var pem = "-----BEGIN RSA PUBLIC KEY-----\n" 
        + pk.replace(/(.{64})/g, "$1\n")
        + "\n-----END RSA PUBLIC KEY-----";

    var rsa = crypto.createVerify("RSA-SHA256");
    rsa.update(new Buffer(challenge, "base64"));
    if(rsa.verify(pem, signature, "base64"))
    {
        return { result : true };
    }
    else {
        return { result : false };
    }
}
1080270
function Signature(req, buf) {
  this.req = req;
  this.rawBody = buf || req.rawBody;

  this.xSignature = (req.headers['x-signature'] || '').split(' ');
  this.signature = base64url.toBuffer(this.xSignature[0] || '');
  this.publicKey = base64url.toBuffer(this.xSignature[1] || '');
  this.endorsement = base64url.toBuffer(this.xSignature[2] || '');

  this.date = Date.parse(req.headers.date);
}
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;
    }
  }
785947
function PublicKey(params) {
    this._fingerprint = params.fingerprint;
    this._modulus = params.modulus;
    this._exponent = params.exponent;
}
489416
def sign_message(payload, private_key)
      signature_urlencoded = ''

      key = OpenSSL::PKey::RSA.new(private_key)

      payload_decoded = CGI::unescape(payload.chomp('decode'))

      signature = key.sign(OpenSSL::Digest::MD5.new, payload_decoded)
      signature_base64 = Base64.strict_encode64(signature)
      signature_urlencoded = "#{CGI::escape(signature_base64)}decode"

      return signature_urlencoded
    end
269237
public static boolean verifySignature(RSAPublicKey key, byte[] message, byte[] signature)
            throws InvalidKeyException, NoSuchAlgorithmException, SignatureException {
        return verifySignature(key, message, signature, DEFAULT_SIGNATURE_ALGORITHM);
    }
282118
function(recipientPrivate, senderPublic, _payload) {
    // Errors
    if(!recipientPrivate || !senderPublic || !_payload) throw new Error('Missing argument !');
    if (!Helpers.isPrivateKeyValid(recipientPrivate)) throw new Error('Private key is not valid !');
    if (!Helpers.isPublicKeyValid(senderPublic)) throw new Error('Public key is not valid !');
    // Processing
    let binPayload = convert.hex2ua(_payload);
    let salt = new Uint8Array(binPayload.buffer, 0, 32);
    let iv = new Uint8Array(binPayload.buffer, 32, 16);
    let payload = new Uint8Array(binPayload.buffer, 48);
    let sk = convert.hex2ua_reversed(recipientPrivate);
    let pk = convert.hex2ua(senderPublic);
    let shared = new Uint8Array(32);
    let r = key_derive(shared, salt, sk, pk);
    let encKey = r;
    let encIv = {
        iv: convert.ua2words(iv, 16)
    };
    let encrypted = {
        'ciphertext': convert.ua2words(payload, payload.length)
    };
    let plain = CryptoJS.AES.decrypt(encrypted, encKey, encIv);
    // Result
    let hexplain = CryptoJS.enc.Hex.stringify(plain);
    return hexplain;
}
1232243
def Verify(self, message, signature, hash_algorithm=None):
    """"""
    # This method accepts both PSS and PKCS1v15 padding. PSS is preferred but
    # old clients only support PKCS1v15.

    if hash_algorithm is None:
      hash_algorithm = hashes.SHA256()

    last_e = None
    for padding_algorithm in [
        padding.PSS(
            mgf=padding.MGF1(hash_algorithm),
            salt_length=padding.PSS.MAX_LENGTH),
        padding.PKCS1v15()
    ]:
      try:
        self._value.verify(signature, message, padding_algorithm,
                           hash_algorithm)
        return True

      except exceptions.InvalidSignature as e:
        last_e = e

    raise VerificationError(last_e)
900164
def key_sign(rsakey, message, digest):
    """"""
    padding = _asymmetric.padding.PKCS1v15()
    signature = rsakey.sign(message, padding, digest)
    return signature
1063506
function( keys ) {
		var lookupString = keys.toString();
		var id = this.plainObjectSignatureLookup[lookupString];			
		if (id === undefined) {

			// Create new signature buffer
			var sigbuf = [];
			sigbuf.push( pack2b( keys.length, false ) );
			for (var i=0, l=keys.length; i<l; ++i) {
				sigbuf.push( pack2b( this.stringID(keys[i]), false ) );
			}

			// Keep on table
			this.plainObjectSignatureTable.push( Buffer.concat( sigbuf ) );
			this.plainObjectSignatureLookup[lookupString] 
				= id = this.plainObjectSignatureTable.length - 1;

		}
		return id;
	}
860788
def sign(key, qs):
    """"""
    sig = derive_signature(key, qs)
    return "%s&%s" % (qs, urlencode([("sig", sig)]))
104978
public static void verify(X509Certificate cert, PublicKey key,
            Provider sigProvider) throws CertificateException,
            NoSuchAlgorithmException, InvalidKeyException, SignatureException {
        cert.verify(key, sigProvider);
    }
867138
def verify_token(token, public_key_or_address, signing_algorithm="ES256K"):
    
    decoded_token = decode_token(token)
    decoded_token_payload = decoded_token["payload"]

    if "subject" not in decoded_token_payload:
        raise ValueError("Token doesn't have a subject")
    if "publicKey" not in decoded_token_payload["subject"]:
        raise ValueError("Token doesn't have a subject public key")
    if "issuer" not in decoded_token_payload:
        raise ValueError("Token doesn't have an issuer")
    if "publicKey" not in decoded_token_payload["issuer"]:
        raise ValueError("Token doesn't have an issuer public key")
    if "claim" not in decoded_token_payload:
        raise ValueError("Token doesn't have a claim")

    issuer_public_key = str(decoded_token_payload["issuer"]["publicKey"])
    public_key_object = ECPublicKey(issuer_public_key)

    compressed_public_key = compress(issuer_public_key)
    decompressed_public_key = decompress(issuer_public_key)

    if public_key_object._type == PubkeyType.compressed:
        compressed_address = public_key_object.address()
        uncompressed_address = bin_hash160_to_address(
            bin_hash160(
                decompress(public_key_object.to_bin())
            )
        )
    elif public_key_object._type == PubkeyType.uncompressed:
        compressed_address = bin_hash160_to_address(
            bin_hash160(
                compress(public_key_object.to_bin())
            )
        )
        uncompressed_address = public_key_object.address()
    else:
        raise ValueError("Invalid issuer public key format")
   
    if public_key_or_address == compressed_public_key:
        pass
    elif public_key_or_address == decompressed_public_key:
        pass
    elif public_key_or_address == compressed_address:
        pass
    elif public_key_or_address == uncompressed_address:
        pass
    else:
        raise ValueError("Token public key doesn't match the verifying value")

    token_verifier = TokenVerifier()

    if not token_verifier.verify(token, public_key_object.to_pem()):
        raise ValueError("Token was not signed by the issuer public key")

    return decoded_token
494260
function (message, signature) {
      var md = forge.md.sha1.create();
      md.update(message, 'utf8');
      try {
        return this._cert.publicKey.verify(md.digest().bytes(), forge.util.decode64(signature));
      } catch (e) {
        return false;
      }
    }
996313
public static boolean checkByPublicKey(String data, String sign, String publicKey) throws Exception {
		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
		byte[] encodedKey = base64.decode(publicKey);
		PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
		java.security.Signature signature = java.security.Signature.getInstance("SHA256WithRSA");
		signature.initVerify(pubKey);
		signature.update(data.getBytes("utf-8"));
		return signature.verify(base64.decode(sign.getBytes("UTf-8")));
	}
291410
def Verify(self, public_key):
    
    # TODO(amoser): We have to do this manually for now since cryptography does
    # not yet support cert verification. There is PR 2460:
    # https://github.com/pyca/cryptography/pull/2460/files
    # that will add it, once it's in we should switch to using this.

    # Note that all times here are in UTC.
    now = rdfvalue.RDFDatetime.Now().AsDatetime()
    if now > self._value.not_valid_after:
      raise VerificationError("Certificate expired!")
    if now < self._value.not_valid_before:
      raise VerificationError("Certificate not yet valid!")

    public_key.Verify(
        self._value.tbs_certificate_bytes,
        self._value.signature,
        hash_algorithm=self._value.signature_hash_algorithm)
    return True
801505
public void proveIdentity(byte[] sharedSecret, KeyPair key) throws IOException, GeneralSecurityException {
        String algorithm = detectKeyAlgorithm(key);
        writeUTF(algorithm);
        writeKey(key.getPublic());

        Signature sig = Signature.getInstance("SHA1with"+algorithm);
        sig.initSign(key.getPrivate());
        sig.update(key.getPublic().getEncoded());
        sig.update(sharedSecret);
        writeObject(sig.sign());
    }