當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RSA::sign方法代碼示例

本文整理匯總了PHP中phpseclib\Crypt\RSA::sign方法的典型用法代碼示例。如果您正苦於以下問題:PHP RSA::sign方法的具體用法?PHP RSA::sign怎麽用?PHP RSA::sign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phpseclib\Crypt\RSA的用法示例。


在下文中一共展示了RSA::sign方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: sign

 /**
  * Sign with RSASS-PSS + MGF1+SHA256
  * 
  * @param string $message
  * @param PrivateKey $rsaPrivateKey
  * @return string
  */
 public static function sign($message, PrivateKey $rsaPrivateKey)
 {
     static $rsa = null;
     if (!$rsa) {
         $rsa = new RSA();
         $rsa->setSignatureMode(RSA::SIGNATURE_PSS);
         $rsa->setMGFHash('sha256');
     }
     $rsa->loadKey($rsaPrivateKey->getKey());
     return $rsa->sign($message);
 }
開發者ID:paragonie,項目名稱:easyrsa,代碼行數:18,代碼來源:EasyRSA.php

示例2: createSignatureData

 /**
  * Creates the signature data
  *
  * @param array $hashes
  * @param X509 $certificate
  * @param RSA $privateKey
  * @return string
  */
 private function createSignatureData(array $hashes, X509 $certificate, RSA $privateKey)
 {
     ksort($hashes);
     $privateKey->setSignatureMode(RSA::SIGNATURE_PSS);
     $privateKey->setMGFHash('sha512');
     $signature = $privateKey->sign(json_encode($hashes));
     return ['hashes' => $hashes, 'signature' => base64_encode($signature), 'certificate' => $certificate->saveX509($certificate->currentCert)];
 }
開發者ID:farukuzun,項目名稱:core-1,代碼行數:16,代碼來源:checker.php

示例3: calculateSignature

 /**
  * Static method for quick calls to calculate a signature.
  * @link https://developer.walmartapis.com/#authentication
  * @param string $consumerId
  * @param string $privateKey
  * @param string $requestUrl
  * @param string $requestMethod
  * @param string|null $timestamp
  * @return string
  * @throws \Exception
  */
 public static function calculateSignature($consumerId, $privateKey, $requestUrl, $requestMethod, $timestamp = null)
 {
     if (is_null($timestamp) || !is_numeric($timestamp)) {
         $timestamp = self::getMilliseconds();
     }
     /**
      * Append values into string for signing
      */
     $message = $consumerId . "\n" . $requestUrl . "\n" . strtoupper($requestMethod) . "\n" . $timestamp . "\n";
     /**
      * Get RSA object for signing
      */
     $rsa = new RSA();
     $decodedPrivateKey = base64_decode($privateKey);
     $rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
     $rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
     /**
      * Load private key
      */
     if ($rsa->loadKey($decodedPrivateKey, RSA::PRIVATE_FORMAT_PKCS8)) {
         /**
          * Make sure we use SHA256 for signing
          */
         $rsa->setHash('sha256');
         $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
         $signed = $rsa->sign($message);
         /**
          * Return Base64 Encode generated signature
          */
         return base64_encode($signed);
     } else {
         throw new \Exception("Unable to load private key", 1446780146);
     }
 }
開發者ID:fillup,項目名稱:walmart-auth-signature-php,代碼行數:45,代碼來源:Signature.php


注:本文中的phpseclib\Crypt\RSA::sign方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。