<small id='11g48'></small><noframes id='11g48'>

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

      1. 使用 PHP 和 OpenSSL 将 P12 转换为 PEM

        时间:2023-10-15

          <bdo id='dYHMk'></bdo><ul id='dYHMk'></ul>
          <legend id='dYHMk'><style id='dYHMk'><dir id='dYHMk'><q id='dYHMk'></q></dir></style></legend>

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

              <tfoot id='dYHMk'></tfoot>

                  <small id='dYHMk'></small><noframes id='dYHMk'>

                    <tbody id='dYHMk'></tbody>

                • 本文介绍了使用 PHP 和 OpenSSL 将 P12 转换为 PEM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将一些 .p12 文件转换为 .pem.

                  I'm trying to convert some .p12 files in to .pem.

                  在我的 mac 上它可以工作,没有交互,因为我将密码放入代码中,但是当我使用此代码时:

                  On my mac it works, with no interaction as i put the passwords in the code, but when i use this code:

                  system('openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12 -passin pass:');
                  system('openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12 -passout pass:1234 -passin pass:');
                  system('openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem -passin pass:1234');
                  system('cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem');
                  

                  它会生成空白文件.

                  我的文件权限是 755.对于 passin,密码被设置为空,所以这就是为什么它们是空白的......这里没有 system() 的所有代码都在 mac 终端中工作..

                  My file permissions are 755. and for the passin the passwords were set to nothing so thats why they are blank... all the code here without the system() works in the mac terminal..

                  感谢阅读.希望能帮到你

                  thanks for reading. hope you can help

                  推荐答案

                  $filename = 'apns-dev-cert.p12';
                  $password = '...';
                  $results = array();
                  $worked = openssl_pkcs12_read(file_get_contents($filename), $results, $password));
                  if($worked) {
                      echo '<pre>', print_r($results, true), '</pre>';
                  } else {
                      echo openssl_error_string();
                  }
                  

                  请尝试运行此代码段.将 $password 设置为打开文件所需的任何密码.如果没有密码,请将其设置为空.我认为您的 openssl 命令不需要一个.

                  Please try running this snippet. Set $password to whatever passphrase is needed to open the file. If there's no password, set it to null. I don't believe one is needed from your openssl commands.

                  应该获得所需私钥的输出,可能在$results['pkey']中.

                  You should get output with the desired private key, probably inside $results['pkey'].

                  如果你在那里看到你的私钥,那么你可以把它传递给 openssl_pkey_export 以 PEM 格式获取它,然后您可以将其写入文件:

                  If you see your private key there, then you can pass it to openssl_pkey_export to get it in PEM format, which you can then write to a file:

                  $new_password = null;
                  $result = null;
                  $worked = openssl_pkey_export($results['pkey'], $result, $new_password);
                  if($worked) {
                      echo "<pre>It worked!  Your new pkey is:
                  ", $result, '</pre>';
                  } else {
                      echo openssl_error_string();
                  }
                  

                  如果需要,请将 $new_password 设置为所需的 pkey 密码.

                  Set $new_password to your desired pkey password, if you want one.

                  根据我在各种文档页面上阅读的内容,这 应该适合您.

                  This should work for you, based on what I'm reading on the various documentation pages.

                  如果您真的想继续使用 openssl 命令,请考虑使用 proc_open 而不是 system,以便您可以正确捕获错误消息.

                  If you really want to continue using the openssl command by shelling out, please consider using proc_open instead of system, so that you can properly catch error messages.

                  也有可能是 OpenSSL 正在尝试读取配置文件,并且没有读取权限,尽管它应该给您一个错误.

                  It's also possible that OpenSSL is trying to read the config file, and doesn't have permission to so, though it should give you an error about that.

                  这篇关于使用 PHP 和 OpenSSL 将 P12 转换为 PEM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:openssl_verify 和“错误:0906D06C:PEM 例程:PEM_read_bio:无起始行" 下一篇:在 WAMP/Apache 的 openssl.exe 中找不到序号 372

                  相关文章

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

                    <small id='3Fc5q'></small><noframes id='3Fc5q'>

                  1. <tfoot id='3Fc5q'></tfoot>