{"id":6823,"date":"2024-12-21T10:26:20","date_gmt":"2024-12-21T01:26:20","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6823"},"modified":"2024-10-16T13:45:19","modified_gmt":"2024-10-16T04:45:19","slug":"post-6823","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6823","title":{"rendered":"PHP\u306eOpenSSL\u95a2\u6570\u3067\u6587\u5b57\u5217\u306e\u6697\u53f7\u30fb\u5fa9\u53f7\u5316\u3092\u884c\u3046\u65b9\u6cd5"},"content":{"rendered":"<p>\u3060\u3044\u3076\u524d\u306b<a href=\"https:\/\/taitan916.info\/blog\/archives\/3032\" target=\"_blank\" rel=\"noopener\">PHP\u3067Blowfish\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u7528\u3044\u305f\u6697\u53f7\u5316\u3068\u5fa9\u53f7\u5316\u3059\u308b\u65b9\u6cd5<\/a>\u3092\u30e1\u30e2\u3057\u305f\u304c\u3001\u305d\u3061\u3089\u306fPear\u306eCrypt_Blowfish\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u3044\u3046\u3082\u306e\u3092\u5c0e\u5165\u3059\u308b\u5fc5\u8981\u304c\u3042\u3063\u305f\u3002\u4eca\u56de\u306f\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u5c0e\u5165\u7b49\u306f\u7121\u3057\u3067PHP\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u6a5f\u80fd\u3067\u4f55\u3068\u304b\u3057\u305f\u304b\u3063\u305f\u3002\u4ee5\u4e0b\u306b\u5bfe\u5fdc\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5bfe\u5fdc\u65b9\u6cd5<\/h2>\n<h3>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\n$data = '\u6697\u53f7\u5316\u3057\u305f\u3044\u5185\u5bb9';\r\n$method = 'AES-256-CBC';\r\n$key = openssl_random_pseudo_bytes(16);\r\n$options = 0;\r\n$iv = openssl_random_pseudo_bytes(16);\r\n\r\n$encrypt = openssl_encrypt( $data, $method, $key, $options, $iv );\r\nvar_dump($encrypt); \/\/string(44) \"Nopuo9XSg1\/jWW4BEyXyG+JJu3ND6m2EfCAoFaUcOGg=\"\r\n\r\n$decrypt = openssl_decrypt( $encrypt, $method, $key, $options, $iv );\r\nvar_dump($decrypt); \/\/string(24) \"\u6697\u53f7\u5316\u3057\u305f\u3044\u5185\u5bb9\"<\/pre>\n<h3>\u6ce8\u610f\u70b9<\/h3>\n<p>\u4e0a\u8a18\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u306f$key \/ $iv\u3092openssl_random_pseudo_bytes\u95a2\u6570\u3092\u7528\u3044\u3066\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u751f\u6210\u3057\u3066\u3044\u308b\u304c\u3001\u5b9f\u969b\u306b\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u751f\u6210\u5f8c\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u7b49\u306b\u767b\u9332\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u70b9\u306b\u6ce8\u610f\u3059\u308b(\u30da\u30fc\u30b8\u3092\u8de8\u3044\u3060\u969b\u306b\u6587\u5b57\u5217\u304c\u518d\u751f\u6210\u3055\u308c\u3066\u5fa9\u53f7\u5316\u3067\u304d\u306a\u304b\u3063\u305f\u308a\u3059\u308b\u305f\u3081)\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/h2>\n<h3>openssl_encrypt<\/h3>\n<p><a href=\"https:\/\/www.php.net\/manual\/ja\/function.openssl-encrypt.php\" target=\"_blank\" rel=\"noopener\">https:\/\/www.php.net\/manual\/ja\/function.openssl-encrypt.php<\/a><\/p>\n<h3>openssl_decrypt<\/h3>\n<p><a href=\"https:\/\/www.php.net\/manual\/ja\/function.openssl-decrypt.php\" target=\"_blank\" rel=\"noopener\">https:\/\/www.php.net\/manual\/ja\/function.openssl-decrypt.php<\/a><\/p>\n<h3>openssl_random_pseudo_bytes<\/h3>\n<p><a href=\"https:\/\/www.php.net\/manual\/ja\/function.openssl-random-pseudo-bytes.php\" target=\"_blank\" rel=\"noopener\">https:\/\/www.php.net\/manual\/ja\/function.openssl-random-pseudo-bytes.php<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3060\u3044\u3076\u524d\u306bPHP\u3067Blowfish\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u7528\u3044\u305f\u6697\u53f7\u5316\u3068\u5fa9\u53f7\u5316\u3059\u308b\u65b9\u6cd5\u3092\u30e1 ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6823"}],"version-history":[{"count":3,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6823\/revisions"}],"predecessor-version":[{"id":6828,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6823\/revisions\/6828"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}