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

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

        为什么在 Linux 或 Windows 下私钥字符串不同?

        Why different private key strings under Linux or Windows?(为什么在 Linux 或 Windows 下私钥字符串不同?)

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

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

                  本文介绍了为什么在 Linux 或 Windows 下私钥字符串不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我使用以下 PHP 代码(和相同的配置参数)创建私钥字符串时,它们包含在不同的字符串之间:

                  When I'm creating private key strings with the following PHP code (and same config-parameter), they are enclosed between different strings:

                  $configs = array('config' => 'OpenSSL.cnf',
                                   'digest_alg' => 'sha1',
                                   'x509_extensions' => 'v3_ca',
                                   'req_extensions' => 'v3_req',
                                   'private_key_bits' => 2048,
                                   'private_key_type' => OPENSSL_KEYTYPE_RSA,
                                   'encrypt_key' => false,
                                   'encrypt_key_cipher' => OPENSSL_CIPHER_3DES);
                  
                  $privateKeyResourceId = openssl_pkey_new($this->configs);                       
                  openssl_pkey_export($privateKeyResourceId, $privateKeyString);
                  

                  在 Linux 上 $privateKeyString 看起来像这样:

                  On Linux the $privateKeyString looks like this:

                  -----开始私钥-----NBgkqhkiG9w0BAQE....ASDFasjkfa-----结束私钥-----

                  -----BEGIN PRIVATE KEY-----NBgkqhkiG9w0BAQE....ASDFasjkfa-----END PRIVATE KEY-----

                  在 Windows 上,$privateKeyString 如下所示:

                  On Windows the $privateKeyString looks like this:

                  -----开始 RSA 私钥-----NBgkqhkiG9E....ASDFasjkfa-----结束 RSA 私钥-----

                  -----BEGIN RSA PRIVATE KEY-----NBgkqhkiG9E....ASDFasjkfa-----END RSA PRIVATE KEY-----

                  当我将 Windows 私钥字符串复制到 Linux 时,它会一直工作,直到我从开头/结尾删除RSA"(反之亦然).这是为什么?

                  When I copy the Windows private key string to Linux it works until I remove the 'RSA' from the start/end (same behavior vice versa). Why is this?

                  推荐答案

                  根据 用户注意 php.net 这是一个已知问题:

                  According to a user note php.net this is a known issue:

                  请注意,旧版本的 PHP/OpenSSL 导出带有 '-----BEGIN RSA PRIVATE KEY-----' PEM 标记的 RSA 私钥,其中仅包含 privateKey 字段,因此省略了版本和privateKeyAlgorithm 字段.

                  Please take note that older versions of PHP/OpenSSL exports the RSA private key with '-----BEGIN RSA PRIVATE KEY-----' PEM tag, which includes just the privateKey field, thus omitting the version and privateKeyAlgorithm fields.

                  这样做的效果是,如果您将其转换为 DER,并且然后回到 PEM,但使用 '-----BEGIN PRIVATE KEY-----' PEM 标签,openssl_pkey_get_privatekey() 函数将失败!Senthryl 的代码可用于在 PEM 编码数据前加上版本和再次使用 privateKeyAlgorithm 字段.

                  The effect of that would be that if you're converting it to DER, and then back to PEM, but using '-----BEGIN PRIVATE KEY-----' PEM tag, that the openssl_pkey_get_privatekey() function will fail!Senthryl's code can be used to prefix the PEM encoded data with the version and privateKeyAlgorithm fields again.

                  较新的 PHP/OpenSSL 版本导出 RSA 私钥'-----BEGIN PRIVATE KEY-----' PEM 标签,包括版本和privateKeyAlgorithm 字段.

                  The newer PHP/OpenSSL versions exports the RSA private key with '-----BEGIN PRIVATE KEY-----' PEM tag, which includes the version and privateKeyAlgorithm fields.

                  我注意到我的两台服务器之间存在这些差异:

                  I noticed these differences between my two servers:

                  基于 Fedora Core 12 x64 的 PHP 版本 5.3.3(OpenSSL 1.0.0a-fips,2010 年 6 月 1 日)

                  PHP Version 5.3.3 (OpenSSL 1.0.0a-fips 1 Jun 2010) on Fedora Core 12 x64

                  基于 Fedora Core 10 x64 的 PHP 版本 5.2.9(OpenSSL 0.9.8g 2007 年 10 月 19 日)

                  PHP Version 5.2.9 (OpenSSL 0.9.8g 19 Oct 2007) on Fedora Core 10 x64

                  这篇关于为什么在 Linux 或 Windows 下私钥字符串不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                  How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                  htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                  Joomla include database functions(Joomla 包含数据库功能)
                  nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                  Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)
                      <i id='fdO2o'><tr id='fdO2o'><dt id='fdO2o'><q id='fdO2o'><span id='fdO2o'><b id='fdO2o'><form id='fdO2o'><ins id='fdO2o'></ins><ul id='fdO2o'></ul><sub id='fdO2o'></sub></form><legend id='fdO2o'></legend><bdo id='fdO2o'><pre id='fdO2o'><center id='fdO2o'></center></pre></bdo></b><th id='fdO2o'></th></span></q></dt></tr></i><div id='fdO2o'><tfoot id='fdO2o'></tfoot><dl id='fdO2o'><fieldset id='fdO2o'></fieldset></dl></div>

                      • <bdo id='fdO2o'></bdo><ul id='fdO2o'></ul>

                            <tbody id='fdO2o'></tbody>

                            <legend id='fdO2o'><style id='fdO2o'><dir id='fdO2o'><q id='fdO2o'></q></dir></style></legend>

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

                            <tfoot id='fdO2o'></tfoot>