@param resource         $source
@param VirgilPrivateKey $signerPrivateKey

@return string
@throws VirgilCryptoException
162357
public function generateStreamSignature($source, VirgilPrivateKey $signerPrivateKey)
    {
        try {
            return $this->cryptoService->signStream($source, $signerPrivateKey->getValue());
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
51010
private function getPHPECCSignature(JWKInterface $key, $data)
    {
        $p = $this->getGenerator();
        $d = $this->convertBase64ToGmp($key->get('d'));
        $hash = $this->convertHexToGmp(hash($this->getHashAlgorithm(), $data));

        $k = RandomGeneratorFactory::getRandomGenerator()->generate($p->getOrder());

        $signer = EccFactory::getSigner();

        $private_key = $p->getPrivateKeyFrom($d);
        $signature = $signer->sign($private_key, $hash, $k);

        $part_length = $this->getSignaturePartLength();

        $R = str_pad($this->convertDecToHex($signature->getR()), $part_length, '0', STR_PAD_LEFT);
        $S = str_pad($this->convertDecToHex($signature->getS()), $part_length, '0', STR_PAD_LEFT);

        return $this->convertHexToBin($R.$S);
    }
515847
public static function generateImageTokenSecretSignature($host, $uri, $token, $secret)
    {
        $host = strtolower($host);

        $base = [];

        $magicsLength = sizeof(self::$imageUrlTokenMagics);
        $additional = [$host, $uri, $secret, $token];
        $offset = 0;
        foreach (str_split($token) as $number) {
            $offset += ord($number);
            $magic = self::$imageUrlTokenMagics[$offset % $magicsLength];
            $base[] = $magic;
            $base[] = array_pop($additional);
            $offset += ord($magic[0]);
            $base[] = sha1($offset, true);
            if (!$additional) {
                break;
            }
        }
        $base = join(chr($offset & 0xff), $base);
        $sha1 = str_split(sha1($base, true));
        $base = [];
        for ($i = 0; $i < 24; $i++) {
            $base[] = $sha1[($i + $offset)%sizeof($sha1)];
        }
        $base = join('', $base);
        return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($base));
    }
631228
public function decrypt($encryptedContent, VirgilPrivateKey $recipientPrivateKey)
    {
        try {
            $cipher = $this->cryptoService->createCipher();
            $cipherInputOutput = $cipher->createInputOutput($encryptedContent);

            return $cipher->decryptWithKey(
                $cipherInputOutput,
                $recipientPrivateKey->getReceiverID(),
                $recipientPrivateKey->getValue()
            );
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
9481
public function signRequest(
        RequestInterface $request,
        SigningSecretKey $secretKey
    ): RequestInterface {
        $signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
            (string) $request->getBody(),
            $secretKey->getString(true)
        );
        return $request->withAddedHeader(
            (string) static::HEADER_SIGNATURE_NAME,
            Base64UrlSafe::encode($signature)
        );
    }
1090226
function encrypt($text, $keys, $sign_key = null)
    {
        try {
            foreach ($keys as $key) {
                $this->gpg->addEncryptKey($key->reference);
            }

            if ($sign_key) {
                $this->gpg->addSignKey($sign_key->reference, $sign_key->password);

                $res     = $this->gpg->encryptAndSign($text, true);
                $sigInfo = $this->gpg->getLastSignatureInfo();

                $this->last_sig_algorithm = $sigInfo->getHashAlgorithmName();

                return $res;
            }

            return $this->gpg->encrypt($text, true);
        }
        catch (Exception $e) {
            return $this->get_error_from_exception($e);
        }
    }
914618
public function checkSignAndDecrypt($params, $rsaPublicKeyPem, $rsaPrivateKeyPem, $isCheckSign, $isDecrypt, $signType='RSA') {
		$charset = $params['charset'];
		$bizContent = $params['biz_content'];
		if ($isCheckSign) {
			if (!$this->rsaCheckV2($params, $rsaPublicKeyPem, $signType)) {
				echo "<br/>checkSign failure<br/>";
				exit;
			}
		}
		if ($isDecrypt) {
			return $this->rsaDecrypt($bizContent, $rsaPrivateKeyPem, $charset);
		}

		return $bizContent;
	}
495986
public function extractPublicKey(VirgilPrivateKey $privateKey, $password = '')
    {
        try {
            $publicKeyData = $this->cryptoService->extractPublicKey($privateKey->getValue(), $password);

            return $this->importPublicKey($publicKeyData);
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
112091
def sign(xml, private, public):
    '''
    
    '''
    xml = xml.encode('utf-8', 'xmlcharrefreplace')
    signed_info_xml = _generate_signed_info(xml)

    signer = PKCS1_v1_5.PKCS115_SigScheme(private)
    signature_value = signer.sign(SHA.new(c14n(signed_info_xml)))

    signature_xml = PTN_SIGNATURE_XML % {
        'signed_info_xml': signed_info_xml,
        'signature_value': binascii.b2a_base64(signature_value)[:-1],
        'key_info_xml': _generate_key_info_xml_rsa(public.key.n, public.key.e)
    }

    position = xml.rfind('</')
    return xml[0:position] + signature_xml + xml[position:]
531052
public static function generateSigningKeypair() : Keypair
    {
        try {
            $keypair = \sodium_crypto_sign_keypair();
            return new Keypair(
                \sodium_crypto_sign_secretkey($keypair),
                \sodium_crypto_sign_publickey($keypair)
            );
        } catch (SodiumException $e) {
            throw new Exception($e->getMessage());
        }
    }
27433
public function exportPublicKey(VirgilPublicKey $publicKey)
    {
        try {
            return $this->cryptoService->publicKeyToDer($publicKey->getValue());
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
391588
public function sign($privateKeys, $coinSymbol)
    {
        if (is_string($privateKeys)) {
            $privateKeys = array($privateKeys);
        }

        // Create PrivateKey objects from plain hex private keys (public keys compressed)
        $privateKeyCompressedList = PrivateKeyList::fromHexPrivateKeyArray($privateKeys, $coinSymbol, true);

        // Create PrivateKey objects from plain hex private keys (public keys uncompressed)
        // Uncompressed keys are not supported by the API, we use them only to check if user is using them and
        // show a specific exception.
        $privateKeyUncompressedList = PrivateKeyList::fromHexPrivateKeyArray($privateKeys, $coinSymbol, false);

        $this->generateSignatures($privateKeyCompressedList, $privateKeyUncompressedList, $coinSymbol);

        return $this;
    }
325309
public function signTokenRequest(TokenRequest $tokenRequest, $privateKey)
    {
        openssl_sign($tokenRequest->getIssuer() . ':' . $tokenRequest->getUsername(), $signature, $privateKey);

        return $tokenRequest->setSignature(base64_encode($signature));
    }
1282904
public function sign($payload, $key)
    {
        if (!$key instanceof Key) {
            $key = new Key($key);
        }
        $privateKey = $this->keyParser->parsePrivateKey($key->getContent());

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

        $random = RandomGeneratorFactory::getRandomGenerator();
        $randomK = $random->generate($this->config->getGenerator()->getOrder());

        $signer = new EccSigner($this->adapter);
        $signature = $signer->sign($privateKey, $hash, $randomK);

        return new LcobucciJWTSignature($this->serializer->serialize($signature, $this->config->getSignatureLength()));
    }
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);
    }
856474
public static function formatPrivateKey($key, $heads = true)
    {
        $key = str_replace(array("\x0D", "\r", "\n"), "", $key);
        if (!empty($key)) {
            if (strpos($key, '-----BEGIN PRIVATE KEY-----') !== false) {
                $key = OneLogin_Saml2_Utils::getStringBetween($key, '-----BEGIN PRIVATE KEY-----', '-----END PRIVATE KEY-----');
                $key = str_replace(' ', '', $key);

                if ($heads) {
                    $key = "-----BEGIN PRIVATE KEY-----\n".chunk_split($key, 64, "\n")."-----END PRIVATE KEY-----\n";
                }
            } else if (strpos($key, '-----BEGIN RSA PRIVATE KEY-----') !== false) {
                $key = OneLogin_Saml2_Utils::getStringBetween($key, '-----BEGIN RSA PRIVATE KEY-----', '-----END RSA PRIVATE KEY-----');
                $key = str_replace(' ', '', $key);

                if ($heads) {
                    $key = "-----BEGIN RSA PRIVATE KEY-----\n".chunk_split($key, 64, "\n")."-----END RSA PRIVATE KEY-----\n";
                }
            } else {
                $key = str_replace(' ', '', $key);

                if ($heads) {
                    $key = "-----BEGIN RSA PRIVATE KEY-----\n".chunk_split($key, 64, "\n")."-----END RSA PRIVATE KEY-----\n";
                }
            }
        }
        return $key;
    }
397957
public function rsaCheckV1($params, $rsaPublicKeyFilePath,$signType='RSA') {
		$sign = $params['sign'];
		$params['sign_type'] = null;
		$params['sign'] = null;
		return $this->verify($this->getSignContent($params), $sign, $rsaPublicKeyFilePath,$signType);
	}