@param string    $signature

@param string    $data
@param PublicKey $publicKey

@return bool
@throws VirgilCryptoException
430351
public function verifyTokenSignature($signature, $data, PublicKey $publicKey)
    {
        if (!$publicKey instanceof VirgilPublicKey) {
            throw new VirgilCryptoException("instance of VirgilPublicKey expected");
        }

        return $this->virgilCrypto->verifySignature($data, $signature, $publicKey);
    }
618735
public function verifyStreamSignature($source, $signature, VirgilPublicKey $signerPublicKey)
    {
        try {
            return $this->cryptoService->verifyStream($source, $signature, $signerPublicKey->getValue());
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
705230
public static function importSignaturePublicKey(HiddenString $keyData): SignaturePublicKey
    {
        return new SignaturePublicKey(
            new HiddenString(
                self::getKeyDataFromString(
                    Hex::decode($keyData->getString())
                )
            )
        );
    }
677803
public static boolean verify(byte[] data, String publicKey, String sign) throws Exception {
        String keyBytes = Base64Utils.encode(publicKey);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes.getBytes());
        KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
        PublicKey publicK = keyFactory.generatePublic(keySpec);
        Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
        signature.initVerify(publicK);
        signature.update(data);
        return signature.verify(Base64Utils.decode(sign).getBytes());
    }
692073
public function verify($content, $signature, $publicKey)
    {
        try {
            return (new CryptoVirgilSigner($this->hashAlgorithm))->verify($content, $signature, $publicKey);
        } catch (Exception $exception) {
            throw new ContentVerificationException($exception->getMessage(), $exception->getCode());
        }
    }
498287
protected function parseSignature(array $header, $data)
    {
        if ($data == '' || !isset($header['alg']) || $header['alg'] == 'none') {
            return null;
        }

        $hash = $this->deserializer->fromBase64URL($data);

        return new Signature($hash);
    }
375077
public static function verify($message, $signature, PublicKey $rsaPublicKey)
    {
        $rsa = self::getRsa(RSA::SIGNATURE_PSS);

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

        return $rsa->verify($message, $signature);
    }
179577
public static String encryptByPrivateKey(String data, String privateKey) throws Exception {
		PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(base64.decode(privateKey));
		KeyFactory keyf = KeyFactory.getInstance("RSA");
		PrivateKey priKey = keyf.generatePrivate(priPKCS8);
		java.security.Signature signature = java.security.Signature.getInstance("SHA256WithRSA");

		signature.initSign(priKey);
		signature.update(data.getBytes("UTf-8"));
		byte[] signed = signature.sign();
		return base64.encodeToString(signed);
	}
1177158
public static function requestApi(array $data, $publicKey): Collection
    {
        Log::debug('Request To Alipay Api', [self::getInstance()->baseUri(), $data]);

        $data = array_filter($data, function ($value) {
            return ($value == '' || is_null($value)) ? false : true;
        });

        $result = mb_convert_encoding(self::getInstance()->post('', $data), 'utf-8', 'gb2312');
        $result = json_decode($result, true);

        $method = str_replace('.', '_', $data['method']).'_response';

        if (!isset($result['sign']) || !isset($result[$method]['code']) || $result[$method]['code'] != '10000') {
            throw new GatewayException(
                'Get Alipay API Error: [msg]'.$result[$method]['msg'].'[sub_code]'.($result[$method]['sub_code'] ?? ''),
                $result,
                $result[$method]['code']
            );
        }

        if (self::verifySign($result[$method], $publicKey, true, $result['sign'])) {
            return new Collection($result[$method]);
        }

        Log::warning('Alipay Sign Verify FAILED', $result);

        throw new InvalidSignException('Alipay Sign Verify FAILED', $result);
    }
590891
public static byte[] sign(
      Signature signatureAlgorithm, PrivateKey privateKey, byte[] contentBytes)
      throws InvalidKeyException, SignatureException {
    signatureAlgorithm.initSign(privateKey);
    signatureAlgorithm.update(contentBytes);
    return signatureAlgorithm.sign();
  }
905926
public static function encryptRsaPublic(string $data, string $publicKey, string $format = null): string
    {
        $key = \openssl_pkey_get_public($publicKey);

        $encrypted = '';
        if (!\openssl_public_encrypt($data, $encrypted, $key, OPENSSL_PKCS1_OAEP_PADDING)) {
            throw new CryptoException('RSA public encrypt error: ' . openssl_error_string());
        }
        \openssl_pkey_free($key);

        return self::fromRaw($encrypted, $format);
    }
396570
public static function signatureRsa(string $data, string $privateKey, string $format = null): string
    {
        $key = \openssl_pkey_get_private($privateKey);
        if (!\openssl_sign($data, $signature, $key, OPENSSL_ALGO_SHA256)) {
            throw new CryptoException('RSA signature error: ' . openssl_error_string());
        }

        return self::fromRaw($signature, $format);
    }
1266561
public function sign($content, $privateKey)
    {
        try {
            return (new CryptoVirgilSigner($this->hashAlgorithm))->sign($content, $privateKey);
        } catch (Exception $exception) {
            throw new ContentSigningException($exception->getMessage(), $exception->getCode());
        }
    }
161307
function signCSR($signatureAlgorithm = 'sha1WithRSAEncryption')
    {
        if (!is_object($this->privateKey) || empty($this->dn)) {
            return false;
        }

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

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

        if (isset($this->currentCert) && is_array($this->currentCert) && isset($this->currentCert['certificationRequestInfo'])) {
            $this->currentCert['signatureAlgorithm']['algorithm'] =
                $signatureAlgorithm;
            if (!empty($this->dn)) {
                $this->currentCert['certificationRequestInfo']['subject'] = $this->dn;
            }
            $this->currentCert['certificationRequestInfo']['subjectPKInfo'] = $publicKey;
        } else {
            $this->currentCert = array(
                'certificationRequestInfo' =>
                    array(
                        'version' => 'v1',
                        'subject' => $this->dn,
                        'subjectPKInfo' => $publicKey
                    ),
                'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm),
                'signature'          => false // this is going to be overwritten later
            );
        }

        // resync $this->signatureSubject
        // save $certificationRequestInfo in case there are any File_ASN1_Element objects in it
        $certificationRequestInfo = $this->currentCert['certificationRequestInfo'];
        $this->loadCSR($this->saveCSR($this->currentCert));

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

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

        return $result;
    }
1055586
public static function fromSignatureData(string $data,
        AlgorithmIdentifierType $algo): Signature
    {
        if ($algo instanceof RSASignatureAlgorithmIdentifier) {
            return RSASignature::fromSignatureString($data);
        }
        if ($algo instanceof ECSignatureAlgorithmIdentifier) {
            return ECSignature::fromDER($data);
        }
        return new GenericSignature(new BitString($data), $algo);
    }
1264743
private function verifySignature($data, $sig)
    {
        $this->initOpenSSL();
        $ret = openssl_verify($data, $sig, $this->publicKey, 'sha256');
        if ($ret == -1) {
            throw new SignatureException(openssl_error_string());
        }
        return $ret;
    }
1210527
public boolean verify(byte[] data, byte[] sign) {
		lock.lock();
		try {
			signature.initVerify(this.publicKey);
			signature.update(data);
			return signature.verify(sign);
		} catch (Exception e) {
			throw new CryptoException(e);
		} finally {
			lock.unlock();
		}
	}