{"id":1570,"date":"2013-01-25T12:32:28","date_gmt":"2013-01-25T03:32:28","guid":{"rendered":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=1570"},"modified":"2016-10-17T09:43:02","modified_gmt":"2016-10-17T09:43:02","slug":"%e6%9a%97%e5%8f%b7%e3%82%ad%e3%83%bc%e3%82%92%e3%81%9f%e3%81%8f%e3%81%95%e3%82%93%e4%bd%9c%e3%82%8b%e3%83%bc%e3%83%9a%e3%82%a2%e3%82%92%e6%8e%a2%e3%81%99","status":"publish","type":"post","link":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=1570","title":{"rendered":"\u6697\u53f7\u30ad\u30fc\u3092\u305f\u304f\u3055\u3093\u4f5c\u308b\u30fc\u30da\u30a2\u3092\u63a2\u3059"},"content":{"rendered":"<p>RSA\u306e\u6697\u53f7\u30ad\u30fc\u3092\u305f\u304f\u3055\u3093\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u3063\u3066\u3001php\u3067\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002\u3042\u307e\u308a\u65b0\u3057\u3055\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u4e0b\u8a18\u306f\u3001100\u30da\u30a2\u4f5c\u308a\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u4f5c\u6210\u3057\u305f\u30ad\u30fc\u3092\u3001XML\u3067\u66f8\u304d\u51fa\u3057\u307e\u3059\u3002<br \/>\n<!-- \u30d3\u30b8\u30e5\u30a2\u30eb\u3067\u7de8\u96c6\u3059\u308b\u3068\u4e71\u308c\u307e\u3059 --><br \/>\n&nbsp;<\/p>\n<pre><code style=\"color:midnightblue;\">&lt;?php\r\n\r\nrequire_once 'Crypt\/RSA.php';\r\n\r\n\/\/Generates the pair keys\r\nfunction generate_key_pair()\r\n{\r\n   global $public_key,$private_key;\r\n\r\n   $key_pair = new Crypt_RSA_KeyPair(1024);\r\n\r\n\/\/\t$key_pair-&gt;generate(1024);\r\n\r\n   \/\/Returns public key from the pair\r\n   $public_key = $key_pair-&gt;getPublicKey();\r\n\r\n   \/\/Returns private key from the pair\r\n   $private_key = $key_pair-&gt;getPrivateKey();\r\n}\r\n\r\n\/\/Check runtime errors\r\nfunction check_error(&amp;$obj)\r\n{\r\n   if ($obj-&gt;isError()){\r\n      $error = $obj-&gt;getLastError();\r\n      switch ($error-&gt;getCode()) {\r\n      case CRYPT_RSA_ERROR_WRONG_TAIL :\r\n         \/\/ nothing to do\r\n         break;\r\n      default:\r\n         \/\/ echo error message and exit\r\n         echo 'error: ', $error-&gt;getMessage();\r\n         exit;\r\n      }\r\n   }\r\n}\r\n\r\n\r\n\r\n\r\n$xmlstr = \"&lt;?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?&gt;\\n\\n&lt;root&gt;\\n\\n\";\r\n\r\n$total = 100;\r\n\r\n\r\nfor ($i = 0; $i &lt; $total; $i++) {\r\n\r\n$xmlstr = $xmlstr.\"&lt;key&gt;\\n&lt;number&gt;$i&lt;\/number&gt;\\n&lt;public&gt;\";\r\n\r\ngenerate_key_pair();\r\n\r\n\/\/get string represenation of the public key\r\n$key = Crypt_RSA_Key::fromString($public_key-&gt;toString());\r\ncheck_error($key);\r\n\r\n$xmlstr = $xmlstr.$public_key-&gt;toString().\"&lt;\/public&gt;\\n&lt;private&gt;\";\r\n\r\n\r\n\r\n\/\/Get string represenation of the private key\r\n$key2 = Crypt_RSA_Key::fromString($private_key-&gt;toString());\r\ncheck_error($key2);\r\n\r\n$xmlstr = $xmlstr.$private_key-&gt;toString().\"&lt;\/private&gt;\\n&lt;\/key&gt;\\n\\n\";\r\n\r\n\r\n\r\n}\r\n\r\n$xmlstr = $xmlstr.\"&lt;\/root&gt;\\n\";\r\n\r\n\/\/echo $xmlstr.\"\\n\";\r\n\r\n\r\n$key_file = @fopen('key.txt','w');\r\n$tmp = fwrite($key_file,$xmlstr);\r\n@fclose(key_file);\r\n\r\n\r\n?&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u66f8\u304d\u51fa\u3057\u305f\u30ad\u30fc\u3092\u898b\u3066\u307f\u305f\u3089\u3001\u6700\u521d\u306e20\u6587\u5b57\u3050\u3089\u3044\u306f\u540c\u3058\u3067\u3057\u305f\uff08\u3061\u3087\u3063\u3068\u9a5a\u304d\u307e\u3059\uff09\u3002\u3082\u3046\u4e00\u5ea6\u5b9f\u884c\u3057\u3066\u3001\u518d\u5ea6\u30ad\u30fc\u3092\u4f5c\u3063\u305f\u3089\u3001\u5225\u306a\u30ad\u30fc\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u304d\u3061\u3093\u3068\u30e9\u30f3\u30c0\u30e0\u306b\u4f5c\u6210\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n\u516c\u958b\u9375\u3068\u79d8\u5bc6\u9375\u306e\u30da\u30a2\u3092\u63a2\u3059\u30b3\u30fc\u30c9\u3082\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre><code style=\"color:midnightblue;\">&lt;?php\r\n\r\n$file = 'key.txt';\r\n\r\n$keytxt = file_get_contents($file);\r\n\r\n$keyxml = simplexml_load_string($keytxt);\r\n\r\n\r\n$target_key = 'YTozOntpOjA7czoxMjg6IksoxLghImuW+UMssDbhDahFco801bKIfcOMfhTIKn\/FoIdZLnoXc7e63oAFu25Cy4io9HEw6MCteonOc+fpjWTi6KQB\/oDyAm23cHml3IAQpn92otOVZ0tuWCNszqpCY1\/A3xXBHJ8pEZfQCw8Y1ORb1ovcd98aAjFAUsi+E9+QIjtpOjE7czo2NDoiRQA7NvHr5uGcl1JNSAM++TPp497ZlI+KRUB7NjEs5+Gcl1JNSAP+uDMo493Yk45JRH86NTAr5uDb1pGMh0L9dyI7aToyO3M6NjoicHVibGljIjt9';\r\n\r\nfor ($i = 0; $i &lt; $keyxml-&gt;key-&gt;count(); $i++) {\r\n\r\nif ($keyxml-&gt;key[$i]-&gt;public == $target_key) {\r\n\techo $keyxml-&gt;key[$i]-&gt;number.\"\\n\";\r\n}\r\n\r\n}\r\n\r\n?&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u3093\u306a\u9577\u3044\u6587\u5b57\u5217\u306e\u4e00\u81f4\u3092\u8abf\u3079\u308b\u6642\u306ecpu\u8ca0\u8377\u306f\u3001\u3069\u308c\u3050\u3089\u3044\u306e\u3082\u306e\u3067\u3057\u3087\u3046\u304b\uff1f\u6642\u9593\u306f\u307b\u307c\u30bc\u30ed\u306a\u306e\u3067\u3059\u304c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RSA\u306e\u6697\u53f7\u30ad\u30fc\u3092\u305f\u304f\u3055\u3093\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u3063\u3066\u3001php\u3067\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002\u3042\u307e\u308a\u65b0\u3057\u3055 &#8230; <a class=\"more-link\" href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=1570\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1570","post","type-post","status-publish","format-standard","hentry","category-column"],"_links":{"self":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1570"}],"version-history":[{"count":3,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1570\/revisions"}],"predecessor-version":[{"id":5466,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1570\/revisions\/5466"}],"wp:attachment":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1570"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}