Sign a CSR

@access public
@return Mixed
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;
    }
735973
public function DKIM_Sign($s) {
    $privKeyStr = file_get_contents($this->DKIM_private);
    if ($this->DKIM_passphrase!='') {
      $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
    } else {
      $privKey = $privKeyStr;
    }
    if (openssl_sign($s, $signature, $privKey)) {
      return base64_encode($signature);
    }
  }
374352
public function sign()
    {
        if ($this->isZero()) {
            return 0;
        }

        if ($this->isReal()) {
            return $this->value['real']->sign();
        }

        return $this->modulus()->sign();
    }
350207
public function registerCSRFString()
    {
        mt_srand(time());
        $string = md5(mt_rand().'_'.time().'_'.mt_rand().'_'.mt_rand());
        $_SESSION[$this->csrfTokenString] = $string;
    }
846329
private function getCsrfToken()
    {
        if(!isset($this->vitex->req->session['_csrf_token'])){
            $token = md5(rand(0,999).time());
            $this->vitex->req->session['_csrf_token'] = $token;
        } else {
            $token = $this->vitex->req->session['_csrf_token'];
        }
        $this->saveScrefToken($token);
        $this->vitex->applyHook("sys.after.generate_csrf_token",$token);
        return $token;
    }
90355
public function sign()
	{
		// the document must be set up
		if (is_null($this->doc))
		{
			return new \UnexpectedValueException('No document structure to sign');
		}
		
		// find the SignedInfo element, which is what we will actually sign
		$signedInfo = $this->doc->getElementsByTagName($this->nodeNsPrefix . 'SignedInfo')->item(0);		
		if (is_null($signedInfo))
		{
			throw new \UnexpectedValueException('Unabled to locate the SignedInfo node');
		}
		
		// canonicalize the SignedInfo element for signing
		$c14nSignedInfo = $this->canonicalize($signedInfo);

		// make sure that we know which OpenSSL algo type to use
		if (!array_key_exists($this->digestMethod, $this->openSSLAlgoMapping))
		{
			throw new \UnexpectedValueException('No OpenSSL algorithm has been defined for digest of type ' . $this->digestMethod);
		}
		
		// sign the SignedInfo element using the private key
		if (!openssl_sign($c14nSignedInfo, $signature, $this->privateKey, $this->openSSLAlgoMapping[$this->digestMethod]))
		{
			throw new \UnexpectedValueException('Unable to sign the document. Error: ' . openssl_error_string());
		}
		
		$signature = base64_encode($signature);
		
		// find the signature value node, to which we will append the base64 encoded signature
		$signatureNode = $this->doc->getElementsByTagName($this->nodeNsPrefix . 'SignatureValue')->item(0);		
		if (is_null($signatureNode))
		{
			throw new \UnexpectedValueException('Unabled to locate the SingatureValue node');
		}
		
		$signatureNode->appendChild($this->doc->createTextNode($signature));
		
		return true;
	}
74112
public function getSigningAlgorithm()
    {
        if (isset($this->raw->algorithm)) {
            if (is_string($this->raw->algorithm)) {
                if (false === defined('Phar::' . $this->raw->algorithm)) {
                    throw new InvalidArgumentException(
                        sprintf(
                            'The signing algorithm "%s" is not supported.',
                            $this->raw->algorithm
                        )
                    );
                }

                return constant('Phar::' . $this->raw->algorithm);
            }

            return $this->raw->algorithm;
        }

        return Phar::SHA1;
    }
34375
function loadCSR($csr, $mode = self::FORMAT_AUTO_DETECT)
    {
        if (is_array($csr) && isset($csr['certificationRequestInfo'])) {
            unset($this->currentCert);
            unset($this->currentKeyIdentifier);
            unset($this->signatureSubject);
            $this->dn = $csr['certificationRequestInfo']['subject'];
            if (!isset($this->dn)) {
                return false;
            }

            $this->currentCert = $csr;
            return $csr;
        }

        // see http://tools.ietf.org/html/rfc2986

        $asn1 = new ASN1();

        if ($mode != self::FORMAT_DER) {
            $newcsr = $this->_extractBER($csr);
            if ($mode == self::FORMAT_PEM && $csr == $newcsr) {
                return false;
            }
            $csr = $newcsr;
        }
        $orig = $csr;

        if ($csr === false) {
            $this->currentCert = false;
            return false;
        }

        $asn1->loadOIDs($this->oids);
        $decoded = $asn1->decodeBER($csr);

        if (empty($decoded)) {
            $this->currentCert = false;
            return false;
        }

        $csr = $asn1->asn1map($decoded[0], $this->CertificationRequest);
        if (!isset($csr) || $csr === false) {
            $this->currentCert = false;
            return false;
        }

        $this->_mapInAttributes($csr, 'certificationRequestInfo/attributes', $asn1);
        $this->_mapInDNs($csr, 'certificationRequestInfo/subject/rdnSequence', $asn1);

        $this->dn = $csr['certificationRequestInfo']['subject'];

        $this->signatureSubject = substr($orig, $decoded[0]['content'][0]['start'], $decoded[0]['content'][0]['length']);

        $algorithm = &$csr['certificationRequestInfo']['subjectPKInfo']['algorithm']['algorithm'];
        $key = &$csr['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey'];
        $key = $this->_reformatKey($algorithm, $key);

        switch ($algorithm) {
            case 'rsaEncryption':
                $this->publicKey = new RSA();
                $this->publicKey->loadKey($key);
                $this->publicKey->setPublicKey();
                break;
            default:
                $this->publicKey = null;
        }

        $this->currentKeyIdentifier = null;
        $this->currentCert = $csr;

        return $csr;
    }
1103033
public function generateSignature()
    {
        $signatureArray = array();

        // Create a pre-hash string based on the security credentials
        // The order is important
        foreach ($this->validSecurityKeys as $key) {
            if (array_key_exists($key, $this->securityPacket)) {
                array_push($signatureArray, $this->securityPacket[$key]);
            }
        }

        // Add the secret
        array_push($signatureArray, $this->secret);

        // Add the requestPacket if necessary
        if ($this->signRequestData && !empty($this->requestString)) {
            array_push($signatureArray, $this->requestString);
        }

        // Add the action if necessary
        if (!empty($this->action)) {
            array_push($signatureArray, $this->action);
        }

        return $this->hashValue($signatureArray);
    }
1198879
public function signCertificateRequest(CertificateRequest $certificateRequest)
    {
        $csrObject = $this->createCsrWithSANsObject($certificateRequest);

        if (!$csrObject || !openssl_csr_export($csrObject, $csrExport)) {
            throw new CSRSigningException(sprintf('OpenSSL CSR signing failed with error: %s', openssl_error_string()));
        }

        return $csrExport;
    }
301182
public function sign() : self
    {
        $b = [];

        foreach ($this->a as $row) {
            $temp = [];

            foreach ($row as $value) {
                if ($value > 0) {
                    $temp[] = 1;
                } elseif ($value < 0) {
                    $temp[] = -1;
                } else {
                    $temp[] = 0;
                }
            }

            $b[] = $temp;
        }

        return self::quick($b);
    }
21468
protected function verifyCsrfToken()
    {
        if (!Config::get('cms.enableCsrfProtection')) {
            return true;
        }

        if (in_array(Request::method(), ['HEAD', 'GET', 'OPTIONS'])) {
            return true;
        }

        $token = Request::input('_token') ?: Request::header('X-CSRF-TOKEN');

        if (!strlen($token)) {
            return false;
        }

        return hash_equals(
            Session::token(),
            $token
        );
    }
1054384
public function getSigningRequest()
    {
        return $this->forge->getCertificateSigningRequest($this->serverId, $this->siteId, $this->id);
    }
348598
protected function checkToken()
    {
        $query = $this->query;
        $signature = $this->sign(
            $this->token,
            isset($query['timestamp']) ? $query['timestamp'] : '',
            isset($query['nonce']) ? $query['nonce'] : ''
        );
        return isset($query['signature']) && $signature === $query['signature'];
    }
818573
public function csrfFixupNeeded() {
        $result = false;
        $isEnterprise = false; // ce
        if (method_exists('Mage', 'getEdition')) {
            if (Mage::getEdition() === Mage::EDITION_ENTERPRISE) {
                $isEnterprise = true;
            }
        } else {
            if (Mage::getConfig()->getModuleConfig('Enterprise_Enterprise')) {
                $isEnterprise = true;
            }
        }
        if ($isEnterprise) {
            if (version_compare(Mage::getVersion(), '1.13', '>=')) {
                $result = true;
            }
        } else {
            if (version_compare(Mage::getVersion(), '1.8', '>=')) {
                $result = true;
            }
        }
        return $result;
    }
334311
public function MakeSign()
	{
		//签名步骤一：按字典序排序参数
		ksort($this->values);
		$string = $this->ToUrlParams();
		//签名步骤二：在string后加入KEY
		$string = $string . "&key=".WxPayConfig::$KEY;
		//签名步骤三：MD5加密
		$string = md5($string);
		//签名步骤四：所有字符转为大写
		$result = strtoupper($string);
		return $result;
	}
99326
public function get(): string
    {
        if (!$this->storage->exists('csrfToken')) {
            $this->generate();
        }

        return $this->storage->get('csrfToken');
    }