当前位置: 首页>>代码示例>>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;未经允许,请勿转载。