• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP openssl_pkey_get_private函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中openssl_pkey_get_private函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_pkey_get_private函数的具体用法?PHP openssl_pkey_get_private怎么用?PHP openssl_pkey_get_private使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了openssl_pkey_get_private函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: rsa_decrypt

 function rsa_decrypt($ciphertext, $private_key, $password)
 {
     // 암호문을 base64로 디코딩한다.
     $ciphertext = @base64_decode($ciphertext, true);
     if ($ciphertext === false) {
         return false;
     }
     // 개인키를 사용하여 복호화한다.
     $privkey_decoded = @openssl_pkey_get_private($private_key, $password);
     if ($privkey_decoded === false) {
         return false;
     }
     $plaintext = false;
     $status = @openssl_private_decrypt($ciphertext, $plaintext, $privkey_decoded);
     @openssl_pkey_free($privkey_decoded);
     if (!$status || $plaintext === false) {
         return false;
     }
     // 압축을 해제하여 평문을 얻는다.
     $plaintext = @gzuncompress($plaintext);
     if ($plaintext === false) {
         return false;
     }
     // 이상이 없는 경우 평문을 반환한다.
     return $plaintext;
 }
开发者ID:mclkim,项目名称:kaiser,代码行数:26,代码来源:rsaCrypt.php


示例2: testFileContentsKey

 /**
  * Test the plugin configuration form.
  *
  * @group key
  */
 public function testFileContentsKey()
 {
     $form = [];
     // Mock the translation manager translate method. This test does not assert
     // any other translation messages so the return value will always be the
     // same message on each consecutive call to t().
     $this->translationManager->expects($this->any())->method('translate')->withConsecutive(['File location'], ['The location of the file in which the key will be stored. The path may be absolute (e.g., %abs), relative to the Drupal directory (e.g., %rel), or defined using a stream wrapper (e.g., %str).'], ['File does not exist or is not readable.'])->willReturn('File does not exist or is not readable.');
     $form['key_settings'] = $this->plugin->buildConfigurationForm($form, $this->form_state);
     $this->assertNotNull($form['key_settings']['file_location']);
     // Test that the file is validated.
     $this->form_state->setValues(['file_location' => 'bogus']);
     $this->plugin->validateConfigurationForm($form, $this->form_state);
     $this->assertEquals('File does not exist or is not readable.', $this->form_state->getErrors()['file_location']);
     // Set the form state value, and simulate a form submission.
     $this->form_state->clearErrors();
     $this->form_state->setValues(['file_location' => $this->keyFile]);
     $this->plugin->validateConfigurationForm($form, $this->form_state);
     $this->assertEmpty($this->form_state->getErrors());
     // Submission.
     $this->plugin->submitConfigurationForm($form, $this->form_state);
     $this->assertEquals($this->keyFile, $this->plugin->getConfiguration()['file_location']);
     // Make sure that the file contents are valid.
     $resource = openssl_pkey_get_private($this->plugin->getKeyValue());
     $this->assertNotFalse($resource);
 }
开发者ID:nerdstein,项目名称:key,代码行数:30,代码来源:FileKeyProviderTest.php


示例3: sign

 public function sign($data, $key, $passphrase = '')
 {
     $privateKey = openssl_pkey_get_private($key, $passphrase);
     openssl_sign($data, $signature, $privateKey);
     openssl_free_key($privateKey);
     return $signature;
 }
开发者ID:claudusd,项目名称:cryptography,代码行数:7,代码来源:SignatureSignPrivateKey.php


示例4: getKey

 public function getKey()
 {
     if (false === isset($this->key)) {
         $this->key = openssl_pkey_get_private(file_get_contents($this->getKeylocation()));
     }
     return $this->key;
 }
开发者ID:leaseweb,项目名称:chefauth-guzzle-plugin,代码行数:7,代码来源:ChefAuthPlugin.php


示例5: privateKey

 public static function privateKey($uri, $ts)
 {
     if (self::privateExists($uri, $ts)) {
         return openssl_pkey_get_private(array('file://' . self::_basePath() . '/' . md5($uri . $ts) . '.pri', ''));
     }
     return false;
 }
开发者ID:neel,项目名称:bong,代码行数:7,代码来源:secure.php


示例6: getPrivateKey

 /**
  * Returns a private key from file path or content
  *
  * @param string $key
  * @param string $passphrase
  *
  * @return resource
  *
  * @throws InvalidArgumentException
  */
 public function getPrivateKey($key, $passphrase = '')
 {
     if ($privateKey = openssl_pkey_get_private($key, $passphrase)) {
         return $privateKey;
     }
     throw new InvalidArgumentException('You should provid a valid private key (with its passphrase when used)');
 }
开发者ID:nguyenbs,项目名称:jwt,代码行数:17,代码来源:Keychain.php


示例7: fetch_private_cert

 protected function fetch_private_cert(&$request)
 {
     $file = Shindig_Config::get('private_key_file');
     if (!(file_exists($file) && is_readable($file))) {
         throw new Exception("Error loding private key");
     }
     $private_key = @file_get_contents($file);
     if (!$private_key) {
         throw new Exception("Error loding private key");
     }
     $phrase = Shindig_Config::get('private_key_phrase');
     if (strpos($private_key, '-----BEGIN') === false) {
         $tmp .= "-----BEGIN PRIVATE KEY-----\n";
         $chunks .= str_split($private_key, 64);
         foreach ($chunks as $chunk) {
             $tmp .= $chunk . "\n";
         }
         $tmp .= "-----END PRIVATE KEY-----";
         $private_key = $tmp;
     }
     if (!($rsa_private_key = @openssl_pkey_get_private($private_key, $phrase))) {
         throw new Exception("Could not create the key");
     }
     return $rsa_private_key;
 }
开发者ID:niryuu,项目名称:opOpenSocialPlugin,代码行数:25,代码来源:OAuthSignature_Method_RSA_SHA1_opOpenSocialPlugin.class.php


示例8: getKeyResource

 /**
  * Converts a string representation of a key into an OpenSSL resource
  *
  * @param string|resource $key
  * @param string          $password
  * @return resource OpenSSL key resource
  */
 protected function getKeyResource($key, $password = null)
 {
     if (is_resource($key)) {
         return $key;
     }
     return openssl_pkey_get_public($key) ?: openssl_pkey_get_private($key, $password);
 }
开发者ID:jonasvr,项目名称:lockedornot,代码行数:14,代码来源:PublicKey.php


示例9: __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


示例10: decryptPrivate

function decryptPrivate($path, $cText)
{
    $fcontents = file_get_contents($path);
    $privateKey = openssl_pkey_get_private($fcontents, "symelosh");
    openssl_private_decrypt($cText, $decrypted, $privateKey);
    return $decrypted;
}
开发者ID:joshin85,项目名称:login,代码行数:7,代码来源:encrypt.php


示例11: 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


示例12: gal_service_account_upgrade

function gal_service_account_upgrade(&$option, $gal_option_name, &$existing_sa_options, $gal_sa_option_name)
{
    /* Convert ga_serviceemail ga_keyfilepath
     * into new separate sa options:
     * ga_sakey, ga_serviceemail, ga_pkey_print
     */
    if (count($existing_sa_options)) {
        return;
    }
    $existing_sa_options = array('ga_serviceemail' => isset($option['ga_serviceemail']) ? $option['ga_serviceemail'] : '', 'ga_sakey' => '', 'ga_pkey_print' => '<unspecified>');
    try {
        if (version_compare(PHP_VERSION, '5.3.0') >= 0 && function_exists('openssl_x509_read')) {
            if (isset($option['ga_keyfilepath']) && $option['ga_keyfilepath'] != '' && file_exists($option['ga_keyfilepath'])) {
                $p12key = @file_get_contents($option['ga_keyfilepath']);
                $certs = array();
                if (openssl_pkcs12_read($p12key, $certs, 'notasecret')) {
                    if (array_key_exists("pkey", $certs) && $certs["pkey"]) {
                        $privateKey = openssl_pkey_get_private($certs['pkey']);
                        $pemString = '';
                        if (openssl_pkey_export($privateKey, $pemString)) {
                            $existing_sa_options['ga_sakey'] = $pemString;
                        }
                        openssl_pkey_free($privateKey);
                        @unlink($options['ga_keyfilepath']);
                    }
                }
            }
        }
    } catch (Exception $e) {
        // Never mind
    }
    // Remove redundant parts of regular options
    unset($option['ga_serviceemail']);
    unset($option['ga_keyfilepath']);
}
开发者ID:Friends-School-Atlanta,项目名称:Deployable-WordPress,代码行数:35,代码来源:service_account_upgrade.php


示例13: __construct

 function __construct($clientcrt, $clientkey, $clientpw = NULL, $logging = false)
 {
     if (is_bool($logging)) {
         $this->logging = $logging;
     }
     if (!openssl_pkey_get_private(is_file($clientkey) ? "file://" . $clientkey : $clientkey, $clientpw)) {
         $this->log("Invalid client private key.", true);
     }
     if (!openssl_pkey_get_public(is_file($clientcrt) ? "file://" . $clientcrt : $clientcrt)) {
         $this->log("Invalid client public key.", true);
     }
     $this->log("Certificate / key looks valid.");
     $handle = curl_init();
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($handle, CURLOPT_HEADER, true);
     curl_setopt($handle, CURLOPT_USERAGENT, sprintf("StartSSL-PHP-API/%s", self::VERSION));
     curl_setopt($handle, CURLOPT_URL, $this->authUrl);
     curl_setopt($handle, CURLOPT_SSLCERT, $clientcrt);
     curl_setopt($handle, CURLOPT_SSLKEY, $clientkey);
     if (!is_null($clientpw)) {
         curl_setopt($handle, CURLOPT_SSLKEYPASSWD, $clientpw);
     }
     $this->log("Authenticating...");
     $result = curl_exec($handle);
     preg_match('/^Set-Cookie: (MyStartSSLCookie=.*)$/m', $result, $matches);
     if (isset($matches[1])) {
         $this->cookie = $matches[1];
         $this->log("User authenticated.");
     } else {
         $this->log("Unable to authenticate. Check certificate/key.", true);
     }
 }
开发者ID:TheDJVG,项目名称:StartSSL-PHP-API,代码行数:32,代码来源:startssl.class.php


示例14: setPrivateKey

 private function setPrivateKey($key, $passPhrase)
 {
     $this->privateKey = @openssl_pkey_get_private($key, $passPhrase);
     if (!$this->validateOpenSslKey($this->privateKey)) {
         throw new InvalidArgumentException('Unable to create private key' . ' from provided key. Key must be a PEM encoded private key or' . ' a path to a file containing a PEM encoded private key.');
     }
 }
开发者ID:jeskew,项目名称:psr6-encrypting-decorator,代码行数:7,代码来源:ItemDecorator.php


示例15: getSignMsg

 /**
  * getSignMsg 计算前面
  *
  * @param array $pay_params
  *        	计算前面数据
  * @param string $sign_type
  *        	签名类型
  * @return string $signMsg 返回密文
  */
 function getSignMsg($pay_params = array(), $sign_type)
 {
     $params_str = "";
     $signMsg = "";
     $sina_config = \System\Entrance::config('SINA_FUND_MANAGED');
     foreach ($pay_params as $key => $val) {
         if ($key != "sign" && $key != "sign_type" && $key != "sign_version" && isset($val) && @$val != "") {
             $params_str .= $key . "=" . $val . "&";
         }
     }
     $params_str = substr($params_str, 0, -1);
     switch (@$sign_type) {
         case 'RSA':
             //签名私钥
             $private_key = $sina_config['private_key'];
             $priv_key = file_get_contents($private_key);
             $pkeyid = openssl_pkey_get_private($priv_key);
             openssl_sign($params_str, $signMsg, $pkeyid, OPENSSL_ALGO_SHA1);
             openssl_free_key($pkeyid);
             $signMsg = base64_encode($signMsg);
             break;
         case 'MD5':
         default:
             $params_str = $params_str . $sina_config['md5_key'];
             $signMsg = strtolower(md5($params_str));
             break;
     }
     return $signMsg;
 }
开发者ID:phpchen,项目名称:yiyuangou,代码行数:38,代码来源:SinaPay.class.php


示例16: generate

 /**
  * @param SigningDetails $dn
  * @param null $privateKey
  * @param null $privkeypass
  * @param int $numberofdays
  * @return array
  * @throws \Exception
  */
 function generate(SigningDetails $dn, $privateKey = null, $privkeypass = null, $numberofdays = 365)
 {
     if ($privateKey === null) {
         $privkey = $this->generatePrivateKey();
     } elseif (is_string($privateKey)) {
         $privkey = openssl_pkey_get_private($privateKey);
     } else {
         throw new \Exception('Invalid format for private key');
     }
     if (!$privkey) {
         throw new \Exception('Invalid private key');
     }
     $csr = @openssl_csr_new($dn->toArray(), $privkey);
     if (!$csr) {
         throw new \Exception('Failed create signing request. Input likely invalid.');
     }
     $sscert = openssl_csr_sign($csr, null, $privkey, $numberofdays);
     if (!$sscert) {
         throw new \Exception('Failed create signing request. Input likely invalid.');
     }
     openssl_x509_export($sscert, $publickey);
     $privatekey = null;
     if (!openssl_pkey_export($privkey, $privatekey, $privkeypass)) {
         throw new \Exception('Private key generatio failed');
     }
     /*$csrStr = null;
     		if(!openssl_csr_export($csr, $csrStr)){
     			throw new \Exception('CSR generation failed');
     		}*/
     return [$publickey, $privatekey];
 }
开发者ID:splitice,项目名称:radical-ssl,代码行数:39,代码来源:X509Helpers.php


示例17: getPublicKey

 /**
  * return PublicKey
  */
 public function getPublicKey()
 {
     $res = \openssl_pkey_get_private($this->keyMaterial);
     $pubkey = \openssl_pkey_get_details($res);
     $public = \rtrim(\str_replace("\n", "\r\n", $pubkey['key']), "\r\n");
     return new PublicKey($public);
 }
开发者ID:paragonie,项目名称:easyrsa,代码行数:10,代码来源:PrivateKey.php


示例18: getSign

function getSign($sMessage)
{
    $sPrivateKey = file_get_contents('private.pem');
    $rPrivateKey = openssl_pkey_get_private($sPrivateKey);
    openssl_sign($sMessage, $sSign, $rPrivateKey, OPENSSL_ALGO_SHA1);
    return bin2hex($sSign);
}
开发者ID:Nebo15,项目名称:ipsp.js,代码行数:7,代码来源:recurring.php


示例19: decryptPassword

function decryptPassword($input)
{
    $config = $GLOBALS['config'];
    if ($config['rsa_modulus'] != '' && $config['rsa_exponent'] != '' && $config['rsa_key'] != '' && isset($_SESSION['crypt_key'])) {
        if (substr($input, 0, 5) == "enc: ") {
            $input = substr($input, 5);
            $res = openssl_pkey_get_private($config['rsa_key'], $config['rsa_passphrase']);
            openssl_private_decrypt(hex2bin($input), $plaintext, $res);
            $plaintext = utf8_encode($plaintext);
            //loop through current session login keys and try all of them that haven't expired
            foreach ($_SESSION['crypt_key'] as $arrayKey => $key_array) {
                //key_array is array(time key was generated, hexadecimal key)
                if (time() - $key_array[0] > 5 * 60) {
                    //delete keys older than 5 minutes
                    //shouldn't take that long to login anyway!
                    unset($_SESSION['crypt_key'][$arrayKey]);
                } else {
                    $crypt_key = $key_array[1];
                    //first part of plaintext should be equal to crypt key
                    if (substr($plaintext, 0, strlen($crypt_key)) == $crypt_key) {
                        return substr($plaintext, strlen($crypt_key));
                    }
                }
            }
            //none of the keys above worked, either forgery or expired form
            return "";
        } else {
            return $input;
        }
    } else {
        return $input;
    }
}
开发者ID:uakfdotb,项目名称:oneapp,代码行数:33,代码来源:crypto.php


示例20: __construct

 public function __construct($accessKey, $secretKey, $encryptionMaterials, $endpoint = NULL)
 {
     parent::__construct($accessKey, $secretKey, $endpoint);
     if (is_array($encryptionMaterials)) {
         if (count($encryptionMaterials) == 2) {
             $pk = openssl_pkey_get_public($encryptionMaterials[0]);
             $sk = openssl_pkey_get_private($encryptionMaterials[1]);
             if (!$pk) {
                 throw new Ks3ClientException("invalid RSA public key,you can generate key use openssl");
             }
             if (!$sk) {
                 throw new Ks3ClientException("invalid RSA private key,you can generate key use openssl");
             }
             $encryptionMaterials = array($pk, $sk);
         } else {
             throw new Ks3ClientException("encryptionMaterials should be string or an array of size 2");
         }
     }
     $ks3client = new Ks3Client($accessKey, $secretKey, $endpoint);
     $this->encryptionMaterials = $encryptionMaterials;
     if (ENCRYPTPTION_MODE == "EO") {
         $this->encryptionHandler = new EncryptionEO($ks3client, $encryptionMaterials);
     } elseif (ENCRYPTPTION_MODE == "AE") {
         throw new Ks3ClientException("Authenticated encryption will be supported in the futher");
     } else {
         throw new Ks3ClientException("unsupported encryption mode :" . ENCRYPTPTION_MODE);
     }
     if (ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata" && ENCRYPTPTION_STORAGE_MODE != "InstructionFile") {
         throw new Ks3ClientException("unsupported encryption storage mode :" . ENCRYPTPTION_STORAGE_MODE);
     }
 }
开发者ID:leunico,项目名称:aliceBlog,代码行数:31,代码来源:Ks3EncryptionClient.class.php



注:本文中的openssl_pkey_get_private函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP openssl_pkey_get_public函数代码示例发布时间:2022-05-15
下一篇:
PHP openssl_pkey_get_details函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap