@param mixed                         $payload
@param \Jose\Object\JWKInterface     $signature_key
@param array                         $protected_headers
@param \Psr\Log\LoggerInterface|null $logger

@return string
341507
public static function createJWSToCompactJSON($payload, JWKInterface $signature_key, array $protected_headers, LoggerInterface $logger = null)
    {
        $jws = self::createJWSAndSign($payload, $signature_key, $protected_headers, [], $logger);

        return $jws->toCompactJSON(0);
    }
1142837
public function decodeResponseFromMps($data_encrypted, $signature)
    {
        try {
            $inputParams = [
                'data_encrypted' => $data_encrypted,
                'signature'      => $signature,
            ];
            $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
            $data = str_replace(' ', '+', $data_encrypted);
            $this->debug->debug(__FUNCTION__, 'Data to Encrypt: ' . json_encode($data));
            $verify = openssl_verify($data, base64_decode($signature), self::getViettelPublicKey(), OPENSSL_ALGO_SHA1);
            $this->debug->debug(__FUNCTION__, 'OpenSSL Verify: ' . json_encode($verify));
            //echo('verify: '.$verify. "\n");
            openssl_private_decrypt(base64_decode($data), $data, self::getCpPrivateKey());
            //echo 'value Decrypt with private key: ' .$data. "\n";
            $arr = [];
            parse_str($data, $arr);
            //B7. Giai ma du lieu bang AES
            $value_decrypt = self::decrypt(str_replace(' ', '+', $arr['VALUE']), $arr['KEY']);
            $this->debug->debug(__FUNCTION__, 'Value to Decrypt: ' . json_encode($value_decrypt));
            $array_response = [];
            parse_str($value_decrypt, $array_response);
            $this->debug->debug(__FUNCTION__, 'Response Array: ' . json_encode($array_response));
            //var_dump($array_response); die;
            //$array_response = explode("&", $value_decrypt);
            $IP          = new IP($this->options);
            $phoneNumber = new Phone_number();
            $phoneNumber->setDebugStatus($this->options['debugStatus']);
            $phoneNumber->setLoggerPath($this->options['debugLoggerPath']);
            $phoneNumber->__construct();
            $IP->setHaProxy(TRUE);
            $this->debug->debug(__FUNCTION__, 'IP Object: ' . json_encode($IP));
            $this->debug->debug(__FUNCTION__, 'PhoneNumber Object: ' . json_encode($phoneNumber));
            if (isset($array_response) && count($array_response) > 0) {
                $resultMsisdn = trim($array_response["MOBILE"]);
                $this->debug->info(__FUNCTION__, 'Result MSISDN: ' . json_encode($resultMsisdn));
                if ($resultMsisdn == NULL || $resultMsisdn == "null") {
                    $msisdn = "GUEST";
                } elseif (strpos($resultMsisdn, self::HIDDEN_STRING) || strpos($resultMsisdn, self::HIDDEN_STRING_2)) {
                    $msisdn = trim($resultMsisdn);
                } else {
                    $msisdn = $phoneNumber->format($resultMsisdn);
                }
                $price        = $array_response["PRICE"];
                $source       = $array_response["SOURCE"];
                $command      = $array_response["CMD"];
                $response_id  = $array_response["RES"];
                $request_id   = $array_response["REQ"];
                $content_logs = "";
            } else {
                $msisdn       = "";
                $price        = "";
                $source       = "";
                $command      = "";
                $response_id  = "";
                $request_id   = "";
                $content_logs = "";
            }
            $outResult = [
                'msisdn'       => $msisdn,
                'request_ip'   => $IP->getIpAddress(),
                'request_id'   => $request_id,
                'response_id'  => $response_id,
                'price'        => $price,
                'source'       => $source,
                'command'      => $command,
                'content_logs' => $content_logs,
            ];
            $this->debug->info(__FUNCTION__, 'Final Result: ' . json_encode($outResult));

            return $outResult;
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);
            $outResult = [
                'msisdn'       => NULL,
                'request_ip'   => NULL,
                'request_id'   => NULL,
                'response_id'  => NULL,
                'price'        => NULL,
                'source'       => NULL,
                'command'      => NULL,
                'content_logs' => NULL,
            ];

            return $outResult;
        }
    }
609358
public function encode(array $payload, $key = null)
    {
        $key = empty($key) ? $this->key : $key;
        if (is_null($key)) {
            if (class_exists('O2System\Framework', false)) {
                $key = config()->getItem('security')->encryptionKey;
            }
        }

        $this->addHeader('alg', $this->algorithm);

        if ( ! empty($this->keyId)) {
            $this->addHeader('kid', $this->keyId);
        }

        // Create Header Segment
        $segments[] = Base64::encode(Json::encode($this->headers));

        // Create Payload Segment
        $segments[] = Base64::encode(Json::encode($payload));

        // Create Signature Segment
        $segments[] = Base64::encode(Signature::generate($segments, $key, $this->algorithm));

        return implode('.', $segments);
    }
863664
public function DKIM_Sign($signHeader)
    {
        if (!defined('PKCS7_TEXT')) {
            if ($this->exceptions) {
                throw new phpmailerException($this->lang('extension_missing') . 'openssl');
            }
            return '';
        }
        $privKeyStr = !empty($this->DKIM_private_string) ? $this->DKIM_private_string : file_get_contents($this->DKIM_private);
        if ('' != $this->DKIM_passphrase) {
            $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
        } else {
            $privKey = openssl_pkey_get_private($privKeyStr);
        }
        //Workaround for missing digest algorithms in old PHP & OpenSSL versions
        //@link http://stackoverflow.com/a/11117338/333340
        if (version_compare(PHP_VERSION, '5.3.0') >= 0 and
            in_array('sha256WithRSAEncryption', openssl_get_md_methods(true))) {
            if (openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption')) {
                openssl_pkey_free($privKey);
                return base64_encode($signature);
            }
        } else {
            $pinfo = openssl_pkey_get_details($privKey);
            $hash = hash('sha256', $signHeader);
            //'Magic' constant for SHA256 from RFC3447
            //@link https://tools.ietf.org/html/rfc3447#page-43
            $t = '3031300d060960864801650304020105000420' . $hash;
            $pslen = $pinfo['bits'] / 8 - (strlen($t) / 2 + 3);
            $eb = pack('H*', '0001' . str_repeat('FF', $pslen) . '00' . $t);

            if (openssl_private_encrypt($eb, $signature, $privKey, OPENSSL_NO_PADDING)) {
                openssl_pkey_free($privKey);
                return base64_encode($signature);
            }
        }
        openssl_pkey_free($privKey);
        return '';
    }
1110217
private function sign(array $payload): string
    {
        $jsonConverter = new StandardConverter();
        $payload = array_merge(
            $payload,
            $this->getAdditionalPayload()
        );
        $headers = $this->getSignatureHeader();
        $signatureKey = $this->signatureKeyset->get($this->signatureKeyIndex);
        if ($signatureKey->has('kid')) {
            $headers['kid'] = $signatureKey->get('kid');
        }

        $jws = $this->jwsBuilder
            ->create()
            ->withPayload($jsonConverter->encode($payload))
            ->addSignature($signatureKey, $headers)
            ->build();

        $serializer = new JWSCompactSerializer($jsonConverter);

        return $serializer->serialize($jws, 0);
    }
1499
function _sign($key, $signatureAlgorithm)
    {
        if ($key instanceof RSA) {
            switch ($signatureAlgorithm) {
                case 'md2WithRSAEncryption':
                case 'md5WithRSAEncryption':
                case 'sha1WithRSAEncryption':
                case 'sha224WithRSAEncryption':
                case 'sha256WithRSAEncryption':
                case 'sha384WithRSAEncryption':
                case 'sha512WithRSAEncryption':
                    $key->setHash(preg_replace('#WithRSAEncryption$#', '', $signatureAlgorithm));
                    $key->setSignatureMode(RSA::SIGNATURE_PKCS1);

                    $this->currentCert['signature'] = base64_encode("\0" . $key->sign($this->signatureSubject));
                    return $this->currentCert;
            }
        }

        return false;
    }
1026032
public static function customPayload(array $payload, string $secret): string
    {
        $builder = self::builder();

        foreach ($payload as $key => $value) {
            if (is_int($key)) {
                throw new ValidateException('Invalid payload claim.', 8);
            }

            $builder->setPayloadClaim($key, $value);
        }

        return $builder->setSecret($secret)
            ->build()
            ->getToken();
    }
578136
def sign(jwk, plain_text, header = nil)
      protected_binary = JOSE.urlsafe_encode64(to_binary)
      payload = JOSE.urlsafe_encode64(plain_text)
      signing_input = signing_input(plain_text, protected_binary)
      signature = JOSE.urlsafe_encode64(alg.sign(jwk, signing_input))
      return signature_to_map(payload, protected_binary, header, jwk, signature)
    end
1211882
private function getInputToVerify(Object\JWSInterface $jws, Object\SignatureInterface $signature, $detached_payload)
    {
        $encoded_protected_headers = $signature->getEncodedProtectedHeaders();
        if (!$signature->hasProtectedHeader('b64') || true === $signature->getProtectedHeader('b64')) {
            if (null !== $jws->getEncodedPayload($signature)) {
                return sprintf('%s.%s', $encoded_protected_headers, $jws->getEncodedPayload($signature));
            }

            $payload = empty($jws->getPayload()) ? $detached_payload : $jws->getPayload();
            $payload = is_string($payload) ? $payload : json_encode($payload);

            return sprintf('%s.%s', $encoded_protected_headers, Base64Url::encode($payload));
        }

        $payload = empty($jws->getPayload()) ? $detached_payload : $jws->getPayload();
        $payload = is_string($payload) ? $payload : json_encode($payload);

        return sprintf('%s.%s', $encoded_protected_headers, $payload);
    }
153261
public function isValid($payload, $secret, $signature)
    {
        return $signature === hash_hmac($this->hashAlgorithm, $payload, $secret, true);
    }
585050
public function signature ( $request, $base_string, $consumer_secret, $token_secret )
	{
		// Fetch the private key cert based on the request
		$cert = $this->fetch_private_cert($request);
		
		// Pull the private key ID from the certificate
		$privatekeyid = openssl_get_privatekey($cert);
		
		// Sign using the key
		$sig = false;
		$ok  = openssl_sign($base_string, $sig, $privatekeyid);   
		
		// Release the key resource
		openssl_free_key($privatekeyid);
		  
		return $request->urlencode(base64_encode($sig));
	}
313143
def sign(payload, keypair):
    """"""
    get_ed25519ll()
    #
    header = {
                "alg": ALG,
                "jwk": {
                    "kty": ALG,  # alg -> kty in jwk-08.
                    "vk": native(urlsafe_b64encode(keypair.vk))
                }
             }

    encoded_header = urlsafe_b64encode(binary(json.dumps(header, sort_keys=True)))
    encoded_payload = urlsafe_b64encode(binary(json.dumps(payload, sort_keys=True)))
    secured_input = b".".join((encoded_header, encoded_payload))
    sig_msg = ed25519ll.crypto_sign(secured_input, keypair.sk)
    signature = sig_msg[:ed25519ll.SIGNATUREBYTES]
    encoded_signature = urlsafe_b64encode(signature)

    return {"recipients":
            [{"header": native(encoded_header),
              "signature": native(encoded_signature)}],
            "payload": native(encoded_payload)}
995346
public function loadAndVerifyWithKey(string $token, JWK $key, ?int &$signature, ?string $payload = null): JWS
    {
        $keyset = JWKSet::createFromKeys([$key]);

        return $this->loadAndVerifyWithKeySet($token, $keyset, $signature, $payload);
    }
882409
public function loadAndVerifyWithKeySet(string $token, JWKSet $keyset, ?int &$signature, ?string $payload = null): JWS
    {
        try {
            $jws = $this->serializerManager->unserialize($token);
            $nbSignatures = $jws->countSignatures();
            for ($i = 0; $i < $nbSignatures; ++$i) {
                if ($this->processSignature($jws, $keyset, $i, $payload)) {
                    $signature = $i;

                    return $jws;
                }
            }
        } catch (\Exception $e) {
            // Nothing to do. Exception thrown just after
        }

        throw new \Exception('Unable to load and verify the token.');
    }
525706
public function getSignHeaderValue()
    {
        $signature = '';
        if (isset($_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE'])) {
            $signature = $_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE'];
        } elseif (isset($_GET['sig'])) {
            $signature = $_GET['sig'];
        }
        if (empty($signature)) {
            throw new \RuntimeException('Signature header not found', 1);
        }

        return $signature;
    }
523981
public function verify(Signer $signer, $payload, $key)
    {
        return $signer->verify($this->hash, $payload, $key);
    }
861431
public static function getSignature($headers)
    {
        foreach($headers as $name => $value)
        {
            if(preg_match('/X-OpenPayU-Signature/i', $name) || preg_match('/OpenPayu-Signature/i', $name))
                return $value;
        }

        return null;
    }