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


PHP openssl_free_key函數代碼示例

本文整理匯總了PHP中openssl_free_key函數的典型用法代碼示例。如果您正苦於以下問題:PHP openssl_free_key函數的具體用法?PHP openssl_free_key怎麽用?PHP openssl_free_key使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: factoryFromEncrypted

 public static function factoryFromEncrypted($envKey, $encData, $privateKeyFilePath, $privateKeyPassword = null)
 {
     $privateKey = null;
     if ($privateKeyPassword == null) {
         $privateKey = @openssl_get_privatekey("file://{$privateKeyFilePath}");
     } else {
         $privateKey = @openssl_get_privatekey("file://{$privateKeyFilePath}", $privateKeyPassword);
     }
     if ($privateKey === false) {
         throw new Exception('Error loading private key', self::ERROR_CONFIRM_LOAD_PRIVATE_KEY);
     }
     $srcData = base64_decode($encData);
     if ($srcData === false) {
         @openssl_free_key($privateKey);
         throw new Exception('Failed decoding data', self::ERROR_CONFIRM_FAILED_DECODING_DATA);
     }
     $srcEnvKey = base64_decode($envKey);
     if ($srcEnvKey === false) {
         throw new Exception('Failed decoding envelope key', self::ERROR_CONFIRM_FAILED_DECODING_ENVELOPE_KEY);
     }
     $data = null;
     $result = @openssl_open($srcData, $data, $srcEnvKey, $privateKey);
     if ($result === false) {
         throw new Exception('Failed decrypting data', self::ERROR_CONFIRM_FAILED_DECRYPT_DATA);
     }
     return Mobilpay_Payment_Request_Abstract::factory($data);
 }
開發者ID:alexandrei892,項目名稱:mobilpay-card-gateway-for-woocommerce,代碼行數:27,代碼來源:class-mobilpay-abstract.php

示例2: __construct

 public function __construct()
 {
     $strCoreKey = "";
     $strPackageKey = "";
     //==================================================================
     $objPackages = $this->db->query("SELECT * FROM __repo_packages WHERE category");
     if ($objPackages) {
         while ($row = $objPackages->fetchAssoc()) {
             if (intval($row['category']) == 8) {
                 $privateKey = $strCoreKey;
             } else {
                 $privateKey = $strPackageKey;
             }
             if ($row['filehash'] != "") {
                 $strHash = $row['filehash'];
                 // fetch private key from file and ready it
                 $strKey = "file://" . $privateKey;
                 $pkeyid = openssl_pkey_get_private($strKey);
                 // compute signature
                 openssl_sign($strHash, $signature, $pkeyid, "sha1WithRSAEncryption");
                 // free the key from memory
                 openssl_free_key($pkeyid);
                 $signature = base64_encode($signature);
                 echo "UPDATE eqdkp20_repo_packages SET signature = '" . $signature . "' WHERE id=" . $row['id'] . "; ";
             }
         }
     }
 }
開發者ID:ZerGabriel,項目名稱:misc-signer,代碼行數:28,代碼來源:signer_localrepo.php

示例3: verify

 /**
  * 驗簽
  *
  * @param string $data
  * @param string $sign
  * @param string $pem
  * @return bool 驗簽狀態
  */
 private function verify($data, $sign)
 {
     $p = openssl_pkey_get_public(file_get_contents($this->chinaums_config['publickKey']));
     $verify = openssl_verify($data, hex2bin($sign), $p);
     openssl_free_key($p);
     return $verify > 0;
 }
開發者ID:yishuixm,項目名稱:online-pay,代碼行數:15,代碼來源:ChinaumsNotify.php

示例4: getXMLSing

	function getXMLSing($xmlHon,$priv_key){
		//Carga Certificado
		$xml = new DomDocument();
		$xml->loadXML($xmlHon);
		//Carga prosedimiento de proceso de cadena original
		$xsl = new DomDocument;
		$xsl->load("ostring.xsl");
		$proc = new xsltprocessor();
		$proc->importStyleSheet($xsl);
		$original =$proc->transformToXML($xml);
		//firma la cadena original
		
		//$fp = $cert[0]['certificates']['key'];
		//$priv_key = $f['key'];
		//die($f['key']);
		//fclose($fp);
		$pkeyid = openssl_get_privatekey($priv_key);
		openssl_sign($original, $signature, $pkeyid,OPENSSL_ALGO_MD5);
		openssl_free_key($pkeyid);
		//coloca el sello en xml
		$esqueletonew=$xmlHon;
		$esqueletonew=str_replace("#1#",base64_encode($signature),$esqueletonew);
		$xmlReturn[1]=$esqueletonew;
		$xmlReturn[2]=$original;
		$xmlReturn[3]=base64_encode($signature);
		return $xmlReturn;
	}
開發者ID:sigmadesarrollo,項目名稱:logisoft,代碼行數:27,代碼來源:ActualizarFacturas.php

示例5: verify

	function verify($pubKey, $toCheck, $signature) {
		$openSslPubKey = openssl_get_publickey($this->seclibToOpenSsl($pubKey));
		$verified = openssl_verify($toCheck, $signature, $openSslPubKey);
		openssl_free_key($openSslPubKey);
		
		return $verified;
	} # verify
開發者ID:remielowik,項目名稱:spotweb,代碼行數:7,代碼來源:SpotSeclibToOpenSsl.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     //
     //Log::info('$request=<' . $request . '>');
     if ($request->isMethod('post')) {
         $bodyContent = $request->getContent();
         //Log::info('$bodyContent=<' . $bodyContent . '>');
         $bodyJson = json_decode($bodyContent);
         $keyPath = $this->keyRoot_ . $bodyJson->token . '/pubKey.pem';
         $fp = fopen($keyPath, 'r');
         $pubKeyMem = fread($fp, 8192);
         fclose($fp);
         $pubkeyid = openssl_pkey_get_public($pubKeyMem);
         $token = $bodyJson->token;
         $sign = $bodyJson->sign;
         $ok = openssl_verify($token, hex2bin($sign), $pubkeyid, "sha256");
         openssl_free_key($pubkeyid);
         if ($ok == 1) {
             $profilePath = $this->keyRoot_ . $bodyJson->token . '/profile';
             //Log::info('$bodyJson->payload=<' . json_encode($bodyJson->payload) . '>');
             file_put_contents($profilePath, json_encode($bodyJson->payload));
             return response()->json(['status' => 'success']);
         } else {
             return response()->json(['status' => 'failure']);
         }
     }
 }
開發者ID:WatorVapor,項目名稱:account,代碼行數:33,代碼來源:ProfileController.php

示例7: decrypt

 /**
  * {@inheritdoc}
  */
 public function decrypt($message, $key)
 {
     $privateKey = openssl_pkey_get_private($key);
     openssl_private_decrypt($message, $messageDecrypted, $privateKey);
     openssl_free_key($privateKey);
     return $messageDecrypted;
 }
開發者ID:claudusd,項目名稱:securechat,代碼行數:10,代碼來源:EncryptionRSA.php

示例8: get_signed_url

function get_signed_url($url, $private_key, $key_pair_id, $expires, $client_ip = null)
{
    $policy = '{' . '"Statement":[' . '{' . '"Resource":"' . $url . '",' . '"Condition":{';
    if (!is_null($client_ip)) {
        $policy .= '"IpAddress":{"AWS:SourceIp":"' . $client_ip . '/32"},';
    }
    $policy .= '"DateLessThan":{"AWS:EpochTime":' . $expires . '}' . '}' . '}' . ']' . '}';
    // the policy contains characters that cannot be part of a URL, so we base64 encode it
    $encoded_policy = url_safe_base64_encode($policy);
    // sign the original policy, not the encoded version
    $signature = '';
    $pkeyid = openssl_get_privatekey($private_key);
    // compute signature
    openssl_sign($policy, $signature, $pkeyid);
    // free the key from memory
    openssl_free_key($pkeyid);
    // make the signature is safe to be included in a url
    $encoded_signature = url_safe_base64_encode($signature);
    // combine the above into a signed url
    // if the signed url already contains query parameters, attach the new query parameters to the end
    // otherwise, add the query parameters
    $separator = strpos($url, '?') == FALSE ? '?' : '&';
    // no IP restriction means we are using a canned policy
    if (!is_null($client_ip)) {
        $url .= $separator . "Expires=" . $expires . "&Signature=" . $encoded_signature . "&Key-Pair-Id=" . $key_pair_id;
    } else {
        $url .= $separator . "Policy=" . $encoded_policy . "&Signature=" . $encoded_signature . "&Key-Pair-Id=" . $key_pair_id;
    }
    // new lines would break us, so remove them
    return str_replace('\\n', '', $url);
}
開發者ID:joshuaiz,項目名稱:vpromo,代碼行數:31,代碼來源:page-promo.php

示例9: rsaVerify

 /**
  * 使用公鑰來驗證RSA簽名合法性
  *
  * @param string $data
  *            需要進行簽名的數據.
  * @param string $publicKey
  *            簽名用戶的公鑰
  * @param string $sign
  *            私鑰簽名
  *            
  * @return bool true/false
  */
 public static function rsaVerify($data, $publicKey, $sign)
 {
     $res = openssl_get_publickey($publicKey);
     $result = (bool) openssl_verify($data, base64_decode($sign), $res);
     openssl_free_key($res);
     return $result;
 }
開發者ID:sdlyhu,項目名稱:Demo,代碼行數:19,代碼來源:OpenSSLUtil.php

示例10: decrypt

 /**
  * {@inheritdoc}
  */
 public function decrypt($data, $key, $passphrase = '')
 {
     $privateKey = openssl_pkey_get_private($key, $passphrase);
     openssl_private_decrypt($data, $messageDecrypted, $privateKey);
     openssl_free_key($privateKey);
     return $messageDecrypted;
 }
開發者ID:claudusd,項目名稱:cryptography,代碼行數:10,代碼來源:EncryptionRSA.php

示例11: decrypt

 /**
  * Decrypts RSA encrypted data using the given private key
  *
  * @throws Cipher\Exception\RuntimeException
  * @param string $encryptedData The encrypted data in binary format
  * @param string $privateKey The private key in binary format
  * @param string $password The private key passphrase
  * @param integer $padding The padding to use during decryption (of not provided object value will be used)
  * @return string The decrypted data
  */
 public function decrypt($encryptedData, $privateKey, $password = null, $padding = null)
 {
     $private_key = openssl_pkey_get_private(array($privateKey, $password));
     if (!$private_key) {
         throw new Cipher\Exception\RuntimeException("Failed to load private key");
     }
     if ($padding !== null) {
         try {
             $this->setPadding($padding);
         } catch (\Exception $e) {
             openssl_free_key($private_key);
             throw $e;
         }
     }
     switch ($this->getPadding()) {
         case self::NO_PADDING:
             $openssl_padding = OPENSSL_NO_PADDING;
             break;
         case self::OAEP_PADDING:
             $openssl_padding = OPENSSL_PKCS1_OAEP_PADDING;
             break;
     }
     $result = openssl_private_decrypt($encryptedData, $decryptedData, $private_key, $openssl_padding);
     openssl_free_key($private_key);
     if (!$result) {
         throw new Cipher\Exception\RuntimeException("Unable to Decrypt Value using provided private key");
     }
     if ($this->getPadding() == self::NO_PADDING) {
         $decryptedData = substr($decryptedData, 2);
         $start = strpos($decryptedData, 0) + 1;
         $decryptedData = substr($decryptedData, $start);
     }
     return $decryptedData;
 }
開發者ID:robertodormepoco,項目名稱:zf2,代碼行數:44,代碼來源:RSA.php

示例12: sign

 /**
  * 簽名數據
  *
  * @param string $data
  *        	要簽名的數據
  * @param string $private
  *        	私鑰文件
  * @return string 簽名的16進製數據
  */
 private function sign($data)
 {
     $p = openssl_pkey_get_private($this->chinaums_config['privateKey']);
     openssl_sign($data, $signature, $p);
     openssl_free_key($p);
     return bin2hex($signature);
 }
開發者ID:yishuixm,項目名稱:online-pay,代碼行數:16,代碼來源:ChinaumsSubmit.php

示例13: obtenSello

 public function obtenSello($cadena_original)
 {
     $pkeyid = openssl_pkey_get_private(file_get_contents($this->path_key), $this->pass_key);
     openssl_sign($cadena_original, $crypttext, $pkeyid, OPENSSL_ALGO_SHA1);
     openssl_free_key($pkeyid);
     $sello = base64_encode($crypttext);
     return $sello;
 }
開發者ID:sujatapadwal,項目名稱:diatomeas,代碼行數:8,代碼來源:cfd.php

示例14: rsa_sha1_sign

function rsa_sha1_sign($policy)
{
    $priv_key = file_get_contents("/Users/joelsaltzman/Desktop/privatekey");
    $pkeyid = openssl_get_privatekey($priv_key);
    openssl_sign($policy, $signature, $pkeyid);
    openssl_free_key($pkeyid);
    return $signature;
}
開發者ID:saltzmanjoelh,項目名稱:RSA_SHA1_Encode_CPP,代碼行數:8,代碼來源:script.php

示例15: verify

 /**
  * makes the verification of the incoming data with a public key
  * @param string $signature
  * @param string $data
  * @param string $publicKeyPath
  * @return boolean
  */
 public static function verify($signature, $data, $publicKeyPath)
 {
     $publicKey = self::read($publicKeyPath);
     $pKeyId = openssl_get_publickey($publicKey);
     $result = openssl_verify($data, $signature, $pKeyId, "SHA256");
     openssl_free_key($pKeyId);
     return (bool) $result;
 }
開發者ID:travijuu,項目名稱:bkm-express,代碼行數:15,代碼來源:Certificate.php


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