{"id":543,"date":"2023-02-25T16:51:06","date_gmt":"2023-02-25T08:51:06","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=543"},"modified":"2023-04-29T20:38:48","modified_gmt":"2023-04-29T12:38:48","slug":"convert-java-private-key-string-to-php-pem-private-key","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/convert-java-private-key-string-to-php-pem-private-key\/","title":{"rendered":"Java\u79c1\u94a5\u5b57\u7b26\u4e32\u8f6c\u4e3aPHP pem\u79c1\u94a5"},"content":{"rendered":"<p>\u64cd\u4f5c\uff1a\u5c06Java\u751f\u6210\u7684\u5bc6\u94a5\u5b57\u7b26\u4e32\u8f6c\u4e3aPHP\u80fd\u8bc6\u522b\u7684pem\u683c\u5f0f\u7684\u5bc6\u94a5\u3002<\/p>\n<p>Java\u751f\u6210\u7684\u5bc6\u94a5\u4e3b\u8981\u662f\u5b57\u7b26\u4e32\uff1b\u800cpem\u683c\u5f0f\u5bc6\u94a5\u662f\u4ee564\u4f4d\u4e3a\u4e00\u884c\uff0c\u5e76\u4e14\u5e26\u6709\u5982\u4e0b\u5934\u548c\u5c3e\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u7136\u540ePHP\u518d\u53bb\u53d6\u5f97\u76f8\u5bf9\u5e94pem\u683c\u5f0f\u5b57\u7b26\u4e32\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>pem\u683c\u5f0f\u5bc6\u94a5<\/h2>\n<pre><code>-----BEGIN PUBLIC KEY-----\n\/\/64chars\u4e00\u884c(\u591a\u884c)\n-----END PUBLIC KEY-----\n-----BEGIN RSA PRIVATE KEY-----\n\/\/64chars\u4e00\u884c(\u591a\u884c)\n-----END RSA PRIVATE KEY-----<\/code><\/pre>\n<h2>Java\u5bc6\u94a5\u8f6c\u4e3apem\u683c\u5f0f\u7684PHP\u4ee3\u7801<\/h2>\n<pre><code class=\"language-php\">$pem_key = format_secret_key($key, &#039;private&#039;);\n\n\/**\n * \u5c06\u5b57\u7b26\u4e32\u683c\u5f0f\u516c\u79c1\u94a5\u683c\u5f0f\u5316\u4e3apem\u683c\u5f0f\u516c\u79c1\u94a5\n * @param $secret_key\n * @param $type\n * @return string\n *\/\nfunction format_secret_key($secret_key, $type) {\n    \/\/64\u4e2a\u82f1\u6587\u5b57\u7b26\u540e\u63a5\u6362\u884c\u7b26&quot;\\n&quot;,\u6700\u540e\u518d\u63a5\u6362\u884c\u7b26&quot;\\n&quot;\n    $key = (wordwrap($secret_key, 64, &quot;\\n&quot;, true)) . &quot;\\n&quot;;\n    \/\/\u6dfb\u52a0pem\u683c\u5f0f\u5934\u548c\u5c3e\n    if ($type == &#039;public&#039;) {\n        $pem_key = &quot;-----BEGIN PUBLIC KEY-----\\n&quot; . $key . &quot;-----END PUBLIC KEY-----\\n&quot;;\n    } else if ($type == &#039;private&#039;) {\n        $pem_key = &quot;-----BEGIN RSA PRIVATE KEY-----\\n&quot; . $key . &quot;-----END RSA PRIVATE KEY-----\\n&quot;;\n    } else {\n        echo(&#039;\u516c\u79c1\u94a5\u7c7b\u578b\u975e\u6cd5&#039;);\n        exit();\n    }\n    return $pem_key;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u64cd\u4f5c\uff1a\u5c06Java\u751f\u6210\u7684\u5bc6\u94a5\u5b57\u7b26\u4e32\u8f6c\u4e3aPHP\u80fd\u8bc6\u522b\u7684pem\u683c\u5f0f\u7684\u5bc6\u94a5\u3002 Java\u751f\u6210\u7684\u5bc6\u94a5\u4e3b\u8981\u662f\u5b57\u7b26\u4e32\uff1b\u800cpem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[97],"tags":[108],"class_list":["post-543","post","type-post","status-publish","format-standard","hentry","category-tools-skills","tag-rsa"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=543"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/543\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}