<bdo id='1HZ2D'></bdo><ul id='1HZ2D'></ul>
    1. <tfoot id='1HZ2D'></tfoot>
    2. <legend id='1HZ2D'><style id='1HZ2D'><dir id='1HZ2D'><q id='1HZ2D'></q></dir></style></legend>
    3. <i id='1HZ2D'><tr id='1HZ2D'><dt id='1HZ2D'><q id='1HZ2D'><span id='1HZ2D'><b id='1HZ2D'><form id='1HZ2D'><ins id='1HZ2D'></ins><ul id='1HZ2D'></ul><sub id='1HZ2D'></sub></form><legend id='1HZ2D'></legend><bdo id='1HZ2D'><pre id='1HZ2D'><center id='1HZ2D'></center></pre></bdo></b><th id='1HZ2D'></th></span></q></dt></tr></i><div id='1HZ2D'><tfoot id='1HZ2D'></tfoot><dl id='1HZ2D'><fieldset id='1HZ2D'></fieldset></dl></div>

      <small id='1HZ2D'></small><noframes id='1HZ2D'>

      1. 如何在 PHP 中创建数字证书并导出到 .p12 文件?

        时间:2023-10-15
        • <legend id='ryzFT'><style id='ryzFT'><dir id='ryzFT'><q id='ryzFT'></q></dir></style></legend>
          <tfoot id='ryzFT'></tfoot>
            <bdo id='ryzFT'></bdo><ul id='ryzFT'></ul>
                <tbody id='ryzFT'></tbody>
              1. <small id='ryzFT'></small><noframes id='ryzFT'>

                <i id='ryzFT'><tr id='ryzFT'><dt id='ryzFT'><q id='ryzFT'><span id='ryzFT'><b id='ryzFT'><form id='ryzFT'><ins id='ryzFT'></ins><ul id='ryzFT'></ul><sub id='ryzFT'></sub></form><legend id='ryzFT'></legend><bdo id='ryzFT'><pre id='ryzFT'><center id='ryzFT'></center></pre></bdo></b><th id='ryzFT'></th></span></q></dt></tr></i><div id='ryzFT'><tfoot id='ryzFT'></tfoot><dl id='ryzFT'><fieldset id='ryzFT'></fieldset></dl></div>

                1. 本文介绍了如何在 PHP 中创建数字证书并导出到 .p12 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在PHP中创建数字证书并导出为.p12文件?

                  How to create a digital certificate and export to .p12 file in PHP?

                  我希望 .p12 文件包含私钥.并且还要检查密钥对是否已经发出(登录数据库).

                  I want the .p12 file to have private key included. And also want to check whether the key pair is already issued (logged in database).

                  我发现了一个名为openssl_pkcs12_export_to_file"的函数,但不知道从哪里开始.看来我需要一个 X509 证书和一个私钥.

                  I found a function called 'openssl_pkcs12_export_to_file' but don't know where to start. Seems that I need an X509 cert and a private key first.

                  推荐答案

                  <?php
                  error_reporting(-1);
                  
                  function dump($Var) {
                    echo "<hr/><pre>";
                    var_dump($Var);
                    echo "</pre><hr/>";
                  }
                  
                  function check_errors() {
                    echo "<hr/><pre>";
                    $Count = 0;
                    while (($e=openssl_error_string())!==false) {
                      echo $e."<br>";
                      $Count++;
                    }
                    if ($Count==0)
                      echo "No error";
                    echo "</pre><hr/>";
                  }
                  
                  $Configs = array(
                    "config" => "e:/progetti/php/openssl/openssl.cfg",
                    "digest_alg" => "sha1",
                    "x509_extensions" => "v3_ca",
                    "req_extensions" => "v3_req",
                    "private_key_bits" => 1024,
                    "private_key_type" => OPENSSL_KEYTYPE_RSA,
                    "encrypt_key" => true,
                    "encrypt_key_cipher" => OPENSSL_CIPHER_3DES 
                  );
                  $Info = array(
                    "countryName" => "VN",
                    "stateOrProvinceName" => "Hanoi",
                    "localityName" => "Long Bien",
                    "organizationName" => "Test Company",
                    "organizationalUnitName" => "Test Department",
                    "commonName" => "Tester",
                    "emailAddress" => "test@gmail.com"
                  );
                  
                  $Private_Key = null;
                  $Unsigned_Cert = openssl_csr_new($Info,$Private_Key,$Configs);
                  check_errors();
                  dump($Private_Key);
                  dump($Unsigned_Cert);
                  
                  $Signed_Cert = openssl_csr_sign($Unsigned_Cert,null,$Private_Key,365,$Configs);
                  check_errors();
                  dump($Signed_Cert);
                  
                  openssl_pkcs12_export_to_file($Signed_Cert,"test.p12",$Private_Key,"123456");
                  check_errors();
                  

                  这篇关于如何在 PHP 中创建数字证书并导出到 .p12 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP OpenSSL 可以生成私钥/公钥/证书对吗? 下一篇:OpenSSL 不会创建私钥?

                  相关文章

                2. <small id='gBdsr'></small><noframes id='gBdsr'>

                    <tfoot id='gBdsr'></tfoot><legend id='gBdsr'><style id='gBdsr'><dir id='gBdsr'><q id='gBdsr'></q></dir></style></legend>

                    <i id='gBdsr'><tr id='gBdsr'><dt id='gBdsr'><q id='gBdsr'><span id='gBdsr'><b id='gBdsr'><form id='gBdsr'><ins id='gBdsr'></ins><ul id='gBdsr'></ul><sub id='gBdsr'></sub></form><legend id='gBdsr'></legend><bdo id='gBdsr'><pre id='gBdsr'><center id='gBdsr'></center></pre></bdo></b><th id='gBdsr'></th></span></q></dt></tr></i><div id='gBdsr'><tfoot id='gBdsr'></tfoot><dl id='gBdsr'><fieldset id='gBdsr'></fieldset></dl></div>
                    • <bdo id='gBdsr'></bdo><ul id='gBdsr'></ul>