{"id":670,"date":"2025-06-11T12:30:57","date_gmt":"2025-06-11T04:30:57","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/xtywj\/670.html"},"modified":"2025-06-11T12:30:57","modified_gmt":"2025-06-11T04:30:57","slug":"php%ef%bc%9a%e5%a6%82%e4%bd%95%e5%8a%a0%e5%af%86%e5%92%8c%e8%a7%a3%e5%af%86%e6%96%87%e4%bb%b6","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/670.html","title":{"rendered":"PHP\uff1a\u5982\u4f55\u52a0\u5bc6\u548c\u89e3\u5bc6\u6587\u4ef6"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; PHP &#20013;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;&#22810;&#31181;&#26041;&#27861;&#26469;&#21152;&#23494;&#21644;&#35299;&#23494;&#25991;&#20214;&#12290;&#20197;&#19979;&#26159;&#20960;&#31181;&#24120;&#35265;&#30340;&#26041;&#27861;&#65306;<\/p>\n<h3>1. &#20351;&#29992; <code>openssl_encrypt<\/code> &#21644; <code>openssl_decrypt<\/code><\/h3>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ &#23450;&#20041;&#35201;&#21152;&#23494;&#30340;&#23383;&#31526;&#20018;\n$plaintext = \"&#36825;&#26159;&#19968;&#20010;&#38656;&#35201;&#21152;&#23494;&#30340;&#20869;&#23481;\";\n\n\/\/ &#23450;&#20041;&#21152;&#23494;&#31639;&#27861;&#12289;&#23494;&#38053;&#21644;&#27169;&#24335;\n$algorithm = 'AES-256-CBC';\n$key = '&#36825;&#26159;&#19968;&#20010;&#38750;&#24120;&#23433;&#20840;&#19988;&#22797;&#26434;&#30340;&#23494;&#38053;';\n$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algorithm));\n\n\/\/ &#21152;&#23494;\n$ciphertext = openssl_encrypt($plaintext, $algorithm, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);\n\n\/\/ &#25171;&#21360;&#21152;&#23494;&#21518;&#30340;&#25968;&#25454;\necho \"&#21152;&#23494;&#21518;: \" . base64_encode($ciphertext) . \"n\";\n\n\/\/ &#35299;&#23494;\n$decryptedtext = openssl_decrypt(base64_decode($ciphertext), $algorithm, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);\n\n\/\/ &#25171;&#21360;&#35299;&#23494;&#21518;&#30340;&#25968;&#25454;\necho \"&#35299;&#23494;&#21518;: \" . $decryptedtext . \"n\";\n?&gt;<\/code><\/pre>\n<h3>2. &#20351;&#29992; <code>mcrypt_encrypt<\/code> &#21644; <code>mcrypt_decrypt<\/code><\/h3>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ &#23450;&#20041;&#35201;&#21152;&#23494;&#30340;&#23383;&#31526;&#20018;\n$plaintext = \"&#36825;&#26159;&#19968;&#20010;&#38656;&#35201;&#21152;&#23494;&#30340;&#20869;&#23481;\";\n\n\/\/ &#23450;&#20041;&#21152;&#23494;&#31639;&#27861;&#12289;&#23494;&#38053;&#21644;&#27169;&#24335;\n$algorithm = MCRYPT_RIJNDAEL_256;\n$key = '&#36825;&#26159;&#19968;&#20010;&#38750;&#24120;&#23433;&#20840;&#19988;&#22797;&#26434;&#30340;&#23494;&#38053;';\n$iv = mcrypt_create_iv(mcrypt_get_block_size($algorithm, MCRYPT_MODE_CBC), MCRYPT_RAND);\n\n\/\/ &#21152;&#23494;\n$ciphertext = mcrypt_encrypt($algorithm, $key, $plaintext, MCRYPT_MODE_CBC, $iv);\n\n\/\/ &#25171;&#21360;&#21152;&#23494;&#21518;&#30340;&#25968;&#25454;\necho \"&#21152;&#23494;&#21518;: \" . base64_encode($ciphertext) . \"n\";\n\n\/\/ &#35299;&#23494;\n$decryptedtext = mcrypt_decrypt($algorithm, $key, base64_decode($ciphertext), MCRYPT_MODE_CBC, $iv);\n\n\/\/ &#25171;&#21360;&#35299;&#23494;&#21518;&#30340;&#25968;&#25454;\necho \"&#35299;&#23494;&#21518;: \" . $decryptedtext . \"n\";\n?&gt;<\/code><\/pre>\n<h3>3. &#20351;&#29992; <code>password_hash<\/code> &#21644; <code>password_verify<\/code><\/h3>\n<p>&#34429;&#28982; <code>password_hash<\/code> &#21644; <code>password_verify<\/code> &#20027;&#35201;&#29992;&#20110;&#23494;&#30721;&#21704;&#24076;&#21644;&#39564;&#35777;&#65292;&#20294;&#23427;&#20204;&#20063;&#21487;&#20197;&#29992;&#20110;&#21152;&#23494;&#21644;&#35299;&#23494;&#25935;&#24863;&#20449;&#24687;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ &#23450;&#20041;&#35201;&#21152;&#23494;&#30340;&#23383;&#31526;&#20018;\n$plaintext = \"&#36825;&#26159;&#19968;&#20010;&#38656;&#35201;&#21152;&#23494;&#30340;&#20869;&#23481;\";\n\n\/\/ &#20351;&#29992; password_hash &#36827;&#34892;&#21152;&#23494;\n$hashed_password = password_hash($plaintext, PASSWORD_DEFAULT);\n\n\/\/ &#25171;&#21360;&#21152;&#23494;&#21518;&#30340;&#25968;&#25454;&#65288;&#36890;&#24120;&#20250;&#26159;&#21313;&#20845;&#36827;&#21046;&#65289;\necho \"&#21152;&#23494;&#21518; (&#21313;&#20845;&#36827;&#21046;): \" . bin2hex($hashed_password) . \"n\";\n\n\/\/ &#20351;&#29992; password_verify &#36827;&#34892;&#35299;&#23494;&#65288;&#20551;&#35774;&#24050;&#32463;&#30693;&#36947;&#27491;&#30830;&#30340;&#23494;&#30721;&#65289;\n$password = \"&#36825;&#26159;&#19968;&#20010;&#27491;&#30830;&#30340;&#23494;&#30721;\"; \/\/ &#26367;&#25442;&#20026;&#23454;&#38469;&#30340;&#23494;&#30721;\nif (password_verify($password, $hashed_password)) {\n    echo \"&#35299;&#23494;&#25104;&#21151;n\";\n} else {\n    echo \"&#35299;&#23494;&#22833;&#36133;n\";\n}\n?&gt;<\/code><\/pre>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#20197;&#19979;&#26159;&#19968;&#20010;&#23436;&#25972;&#30340;&#31034;&#20363;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#20351;&#29992; <code>openssl_encrypt<\/code> &#21644; <code>openssl_decrypt<\/code> &#26469;&#21152;&#23494;&#21644;&#35299;&#23494;&#25991;&#20214;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ &#23450;&#20041;&#35201;&#21152;&#23494;&#30340;&#25991;&#20214;&#36335;&#24452;\n$inputFilePath = 'input.txt';\n$outputFilePath = 'output.enc';\n\n\/\/ &#23450;&#20041;&#21152;&#23494;&#31639;&#27861;&#12289;&#23494;&#38053;&#21644;&#27169;&#24335;\n$algorithm = 'AES-256-CBC';\n$key = '&#36825;&#26159;&#19968;&#20010;&#38750;&#24120;&#23433;&#20840;&#19988;&#22797;&#26434;&#30340;&#23494;&#38053;';\n$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algorithm));\n\n\/\/ &#35835;&#21462;&#36755;&#20837;&#25991;&#20214;&#20869;&#23481;\n$fileContent = file_get_contents($inputFilePath);\n\n\/\/ &#21152;&#23494;&#25991;&#20214;&#20869;&#23481;\n$ciphertext = openssl_encrypt($fileContent, $algorithm, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);\n\n\/\/ &#23558;&#21152;&#23494;&#21518;&#30340;&#25968;&#25454;&#20889;&#20837;&#36755;&#20986;&#25991;&#20214;\nfile_put_contents($outputFilePath, base64_encode($ciphertext));\n\n\/\/ &#26174;&#31034;&#21152;&#23494;&#21518;&#30340;&#25991;&#20214;&#36335;&#24452;\necho \"&#21152;&#23494;&#21518;&#30340;&#25991;&#20214;&#36335;&#24452;: \" . $outputFilePath . \"n\";\n\n\/\/ &#23450;&#20041;&#35299;&#23494;&#21518;&#30340;&#25991;&#20214;&#36335;&#24452;\n$decryptedFilePath = 'output.dec';\n\n\/\/ &#20174;&#36755;&#20986;&#25991;&#20214;&#35835;&#21462;&#21152;&#23494;&#21518;&#30340;&#25968;&#25454;&#24182;&#35299;&#23494;\n$ciphertextBase64 = file_get_contents($outputFilePath);\n$ciphertext = base64_decode($ciphertextBase64);\n$decryptedContent = openssl_decrypt($ciphertext, $algorithm, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);\n\n\/\/ &#23558;&#35299;&#23494;&#21518;&#30340;&#20869;&#23481;&#20889;&#20837;&#36755;&#20986;&#25991;&#20214;\nfile_put_contents($decryptedFilePath, $decryptedContent);\n\n\/\/ &#26174;&#31034;&#35299;&#23494;&#21518;&#30340;&#25991;&#20214;&#36335;&#24452;\necho \"&#35299;&#23494;&#21518;&#30340;&#25991;&#20214;&#36335;&#24452;: \" . $decryptedFilePath . \"n\";\n?&gt;<\/code><\/pre>\n<p>&#36825;&#20010;&#31034;&#20363;&#23637;&#31034;&#20102;&#22914;&#20309;&#20351;&#29992; <code>openssl_encrypt<\/code> &#21644; <code>openssl_decrypt<\/code> &#26469;&#21152;&#23494;&#21644;&#35299;&#23494;&#19968;&#20010;&#25991;&#26412;&#25991;&#20214;&#12290;&#20320;&#21487;&#20197;&#26681;&#25454;&#38656;&#35201;&#20462;&#25913;&#36755;&#20837;&#21644;&#36755;&#20986;&#25991;&#20214;&#36335;&#24452;&#20197;&#21450;&#21152;&#23494;&#21644;&#35299;&#23494;&#31639;&#27861;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#20171;&#32461;<\/h2><p>&#38543;&#30528;&#24320;&#21457;&#20154;&#21592;&#21644;&#29992;&#25143;&#36234;&#26469;&#36234;&#24847;&#35782;&#21040;&#25968;&#25454;&#23433;&#20840;&#30340;&#37325;&#35201;&#24615;&#65292;&#21152;&#23494;&#24050;&#25104;&#20026;&#31649;&#29702;&#24182;&#20256;&#36755;&#25991;&#20214;&#30340;&#20851;&#38190;&#37096;&#20998;&#12290;&#22312;&#26412;&#25945;&#31243;&#20013;&#65292;&#24744;&#23558;&#23398;&#20064;&#22914;&#20309;&#20351;&#29992;PHP&#26469;&#21152;&#23494;&#21644;&#35299;&#23494;&#25991;&#20214;&#65292;&#20197;&#30830;&#20445;&#25968;&#25454;&#30340;&#26426;&#23494;&#24615;&#21644;&#23436;&#25972;&#24615;&#12290;&#25105;&#20204;&#23558;&#28085;&#30422;&#21152;&#23494;&#21644;&#35299;&#23494;&#30340;&#27010;&#24565;&#12289;&#29983;&#25104;&#23433;&#20840;&#23494;&#38053;&#20197;&#21450;&#25552;&#20379;&#19968;&#20010;&#29992;&#20110;&#22788;&#29702;&#36825;&#20123;&#20219;&#21153;&#30340;&#30495;&#23454;&#19990;&#30028;PHP&#33050;&#26412;&#31034;&#20363;&#12290;<\/p><h2>&#21152;&#23494;&#21644;&#35299;&#23494;&#26159;&#25351;&#36890;&#36807;&#29305;&#23450;&#30340;&#31639;&#27861;&#23545;&#25968;&#25454;&#36827;&#34892;&#32534;&#30721;&#25110;&#35299;&#30721;&#30340;&#36807;&#31243;&#65292;&#20197;&#20445;&#25252;&#20449;&#24687;&#30340;&#23433;&#20840;&#24615;&#21644;&#26426;&#23494;&#24615;&#12290;&#21152;&#23494;&#25216;&#26415;&#21487;&#20197;&#38450;&#27490;&#26410;&#32463;&#25480;&#26435;&#30340;&#20154;&#35775;&#38382;&#25935;&#24863;&#25968;&#25454;&#65292;&#32780;&#35299;&#23494;&#21017;&#20801;&#35768;&#21512;&#27861;&#29992;&#25143;&#33719;&#21462;&#36825;&#20123;&#20449;&#24687;&#12290;&#24120;&#35265;&#30340;&#21152;&#23494;&#26041;&#27861;&#21253;&#25324;&#23545;&#31216;&#21152;&#23494;&#12289;&#38750;&#23545;&#31216;&#21152;&#23494;&#31561;&#65292;&#23427;&#20204;&#21508;&#26377;&#29305;&#28857;&#65292;&#36866;&#29992;&#20110;&#19981;&#21516;&#30340;&#24212;&#29992;&#22330;&#26223;&#12290;<\/h2><p>&#21152;&#23494;&#26159;&#19968;&#31181;&#23433;&#20840;&#25514;&#26045;&#65292;&#23427;&#20351;&#29992;&#31639;&#27861;&#23558;&#25968;&#25454;&#36716;&#21270;&#20026;&#19968;&#20010;&#21482;&#33021;&#29992;&#27491;&#30830;&#30340;&#35299;&#23494;&#23494;&#38053;&#25165;&#33021;&#24674;&#22797;&#21040;&#21407;&#22987;&#24418;&#24335;&#30340;&#19981;&#21487;&#35835;&#26684;&#24335;&#12290;&#20027;&#35201;&#30446;&#30340;&#26159;&#20445;&#25252;&#25968;&#25454;&#20813;&#21463;&#26410;&#32463;&#25480;&#26435;&#35775;&#38382;&#12290;<\/p><p>&#35299;&#23494;&#30340;&#36807;&#31243;&#26159;&#20174;&#21152;&#23494;&#25968;&#25454;&#20013;&#23558;&#20854;&#36824;&#21407;&#22238;&#21407;&#22987;&#24418;&#24335;&#65292;&#20197;&#20415;&#21487;&#20197;&#35775;&#38382;&#21644;&#29702;&#35299;&#23427;&#12290;<\/p><h2>&#29983;&#25104;&#21152;&#23494;&#23494;&#38053;<\/h2><p>&#23494;&#30721;&#23398;&#30340;&#21487;&#38752;&#36816;&#34892;&#20381;&#36182;&#20110;&#24378;&#23494;&#38053;&#12290;PHP&#25552;&#20379;&#20102;&#29983;&#25104;&#38543;&#26426;&#23383;&#33410;&#30340;&#21151;&#33021;&#65292;&#36825;&#20123;&#23383;&#33410;&#21487;&#20197;&#20316;&#20026;&#23494;&#38053;&#20351;&#29992;&#12290;<\/p><pre><code>$key = openssl_random_pseudo_bytes(32);\n$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));\n<\/code><\/pre><p>&#25105;&#20204;&#29983;&#25104;&#19968;&#20010;&#36866;&#21512;AES-256&#21152;&#23494;&#30340;256&#20301;&#23494;&#38053;&#65292;&#20197;&#21450;&#19982;Cipher&#22359;&#22823;&#23567;&#21305;&#37197;&#30340;&#21021;&#22987;&#21270;&#21521;&#37327;&#65288;IV&#65289;&#12290;<\/p><h2>&#20351;&#29992;PHP&#21152;&#23494;&#25991;&#20214;<\/h2><p>&#20026;&#20102;&#21152;&#23494;&#25991;&#20214;&#65292;&#21487;&#20197;&#20351;&#29992;PHP&#25552;&#20379;&#30340;OpenSSL&#20989;&#25968;&#12290;&#20197;&#19979;&#31034;&#20363;&#23637;&#31034;&#20102;&#22914;&#20309;&#23545;&#25991;&#20214;&#36827;&#34892;AES-256&#21152;&#23494;&#30340;&#25805;&#20316;&#12290;<\/p><pre><code>function encryptFile($fileToEncrypt, $key, $iv) {\n    $plaintext = file_get_contents($fileToEncrypt);\n    $ciphertext = openssl_encrypt($plaintext, 'aes-256-cbc', $key, $options=0, $iv);\n    file_put_contents($fileToEncrypt . '.enc', $ciphertext);\n}\n<\/code><\/pre><p>&#35813;&#21151;&#33021;&#35835;&#21462;&#25991;&#20214;&#65292;&#21152;&#23494;&#25968;&#25454;&#65292;&#24182;&#20197;&ldquo;.enc&rdquo;&#25193;&#23637;&#21517;&#20445;&#23384;&#65292;&#20197;&#34920;&#31034;&#20854;&#21152;&#23494;&#29366;&#24577;&#12290;<\/p><h2>&#20351;&#29992;PHP&#35299;&#23494;&#25991;&#20214;<\/h2><p>&#35299;&#23494;&#26159;&#21152;&#23494;&#36807;&#31243;&#30340;&#36870;&#21521;&#25805;&#20316;&#12290;&#20351;&#29992;&#20197;&#19979;&#20989;&#25968;&#26469;&#29992;&#30456;&#21516;&#30340;&#23494;&#38053;&#21644;IV&#23545;&#25991;&#20214;&#36827;&#34892;&#35299;&#23494;&#12290;<\/p><pre><code>function decryptFile($encryptedFile, $key, $iv) {\n    $ciphertext = file_get_contents($encryptedFile);\n    $plaintext = openssl_decrypt($ciphertext, 'aes-256-cbc', $key, $options=0, $iv);\n    file_put_contents(str_replace('.enc', '', $encryptedFile), $plaintext);\n}\n<\/code><\/pre><p>&#35813;&#21151;&#33021;&#20250;&#21152;&#23494;&#25991;&#20214;&#65292;&#35299;&#23494;&#20854;&#20869;&#23481;&#65292;&#24182;&#23558;&#20854;&#20445;&#23384;&#20026;&#21407;&#22987;&#25991;&#20214;&#21517;&#65292;&#20294;&#19981;&#24102;&ldquo;.enc&rdquo;&#25193;&#23637;&#21517;&#12290;<\/p><h2>&#31471;&#21040;&#31471;&#31034;&#20363;<\/h2><p>&#35753;&#25105;&#20204;&#26500;&#24314;&#19968;&#20010;&#31471;&#21040;&#31471;&#30340;&#33050;&#26412;&#65292;&#35753;&#29992;&#25143;&#21487;&#20197;&#36873;&#25321;&#26159;&#21542;&#21152;&#23494;&#25110;&#35299;&#23494;&#25991;&#20214;&#65292;&#21516;&#26102;&#22788;&#29702;&#36825;&#20004;&#20010;&#36807;&#31243;&#12290;<\/p><pre><code>\/\/ Define key and IV\n$key = openssl_random_pseudo_bytes(32);\n$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));\n\/\/ Check user input\nif ($argc !== 4 || !in_array($argv[1], ['--encrypt', '--decrypt'])) {\n    echo \"Usage: {$argv[0]} --encrypt|--decrypt file keyFile\n\";\n    exit(1);\n}\n$action = $argv[1];\n$file = $argv[2];\n$keyFile = $argv[3];\n\/\/ Read or save the key and IV\nif ($action === '--encrypt') {\n    file_put_contents($keyFile, json_encode(['key' =&gt; base64_encode($key), 'iv' =&gt; base64_encode($iv)]));\n    encryptFile($file, $key, $iv);\n} elseif ($action === '--decrypt') {\n    if (!file_exists($keyFile)) {\n        echo \"Key file does not exist.\n\";\n        exit(1);\n    }\n    $keyData = json_decode(file_get_contents($keyFile), true);\n    $key = base64_decode($keyData['key']);\n    $iv = base64_decode($keyData['iv']);\n    decryptFile($file, $key, $iv);\n} else {\n    echo \"Invalid action.\n\";\n    exit(1);\n}\n<\/code><\/pre><h2>&#23433;&#20840;&#32771;&#34385;<\/h2><p>&#21152;&#23494;&#24182;&#38750;&#19975;&#33021;&#38053;&#21273;&#12290;&#33391;&#22909;&#30340;&#23494;&#38053;&#31649;&#29702;&#12289;&#23545;&#23433;&#20840;&#39118;&#38505;&#30340;&#24847;&#35782;&#20197;&#21450;&#20351;&#29992;&#32463;&#36807;&#27979;&#35797;&#30340;&#21152;&#23494;&#31639;&#27861;&#37117;&#26159;&#24517;&#19981;&#21487;&#23569;&#30340;&#12290;OpenSSL PHP&#25193;&#23637;&#26159;&#19968;&#20010;&#25104;&#29087;&#19988;&#24191;&#27867;&#20351;&#29992;&#30340;&#27169;&#22359;&#65292;&#25552;&#20379;&#20102;&#24378;&#22823;&#30340;&#21152;&#23494;&#33021;&#21147;&#65292;&#20294;&#20316;&#20026;&#24320;&#21457;&#32773;&#65292;&#24744;&#36824;&#38656;&#35201;&#30830;&#20445;&#24744;&#30340;&#23494;&#38053;&#23384;&#20648;&#24471;&#24403;&#65292;&#24182;&#19988;&#20195;&#30721;&#26412;&#36523;&#27809;&#26377;&#24341;&#20837;&#28431;&#27934;&#12290;<\/p><h2>&#32467;&#35770;<\/h2><p>&#30446;&#21069;&#65292;&#20320;&#24212;&#35813;&#24050;&#32463;&#26377;&#19968;&#20010;&#20351;&#29992;OpenSSL&#36827;&#34892;&#25991;&#20214;&#21152;&#23494;&#21644;&#35299;&#23494;&#30340;&#31034;&#20363;&#24037;&#20316;&#27969;&#31243;&#12290;&#19978;&#38754;&#25552;&#20379;&#30340;&#20195;&#30721;&#21482;&#26159;&#19968;&#20010;&#28436;&#31034;&#27010;&#24565;&#30340;&#31616;&#21333;&#34920;&#31034;&#12290;&#22312;&#29983;&#20135;&#29615;&#22659;&#20013;&#65292;&#20320;&#24212;&#35813;&#21152;&#24378;&#38169;&#35823;&#22788;&#29702;&#21644;&#23433;&#20840;&#24615;&#26816;&#26597;&#12290;<\/p><p>&#21152;&#23494;&#26159;&#20320;&#23433;&#20840;&#24037;&#20855;&#31665;&#20013;&#30340;&#20851;&#38190;&#27494;&#22120;&mdash;&mdash;&#26126;&#26234;&#22320;&#20351;&#29992;&#23427;&#65292;&#30830;&#20445;&#20320;&#30340;&#23494;&#38053;&#23433;&#20840;&#65292;&#24182;&#24443;&#24213;&#27979;&#35797;&#20320;&#30340;&#23454;&#29616;&#12290;&#38543;&#30528;&#25968;&#25454;&#27844;&#38706;&#30340;&#22686;&#21152;&#65292;&#27491;&#30830;&#20445;&#25252;&#20320;&#30340;&#25968;&#25454;&#30340;&#33021;&#21147;&#27604;&#20197;&#24448;&#20219;&#20309;&#26102;&#20505;&#37117;&#26356;&#20026;&#37325;&#35201;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;PHP&#20013;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;openssl&#25193;&#23637;&#26469;&#23545;&#25991;&#20214;&#36827;&#34892;&#21152;&#23494;&#21644;&#35299;&#23494;&#12290;&#20197;&#19979;&#26159;&#22914;&#20309;&#23454;&#29616;&#30340;&#31616;&#35201;&#27493;&#39588;&#65306;<\/p>\n<ol>\n<li>\n<p>&#39318;&#20808;&#65292;&#20320;&#38656;&#35201;&#30830;&#20445;&#20320;&#30340;&#26381;&#21153;&#22120;&#24050;&#32463;&#23433;&#35013;&#20102;php-openssl&#25193;&#23637;&#12290;<\/p>\n<\/li>\n<li>\n<p>&#22312;&#20320;&#30340;PHP&#33050;&#26412;&#20013;&#65292;&#24341;&#20837;openssl&#25193;&#23637;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\nrequire_once 'vendor\/autoload.php';\nuse OpenSSLOPENSSL;<\/code><\/pre>\n<\/li>\n<li>\n<p>&#20351;&#29992;openssl&#25193;&#23637;&#25552;&#20379;&#30340;&#20989;&#25968;&#36827;&#34892;&#25991;&#20214;&#21152;&#23494;&#21644;&#35299;&#23494;&#12290;&#20197;&#19979;&#26159;&#19968;&#20010;&#31616;&#21333;&#30340;&#20363;&#23376;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#23558;&#25991;&#20214;&#21152;&#23494;&#20026;base64&#32534;&#30721;&#30340;&#23383;&#31526;&#20018;&#65292;&#24182;&#23558;&#20854;&#23384;&#20648;&#21040;&#19968;&#20010;&#26032;&#30340;&#25991;&#20214;&#20013;&#12290;<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-php\">\/\/ &#21152;&#36733;openSSL&#25193;&#23637;\n$openssl = OPENSSL::getInternal();\n\n\/\/ &#33719;&#21462;&#21407;&#22987;&#25991;&#20214;&#36335;&#24452;\n$file_path = '\/path\/to\/your\/file.txt';\n\n\/\/ &#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#20020;&#26102;&#25991;&#20214;&#29992;&#20110;&#23384;&#25918;&#21152;&#23494;&#21518;&#30340;&#25968;&#25454;\n$temp_file = tempnam(sys_get_temp_dir(), 'file');\n\n\/\/ &#23558;&#21407;&#22987;&#25991;&#20214;&#35835;&#21462;&#21040;&#20869;&#23384;&#20013;\n$data = file_get_contents($file_path);\n\n\/\/ &#23545;&#25968;&#25454;&#36827;&#34892;&#21152;&#23494;\n$cipher = $openssl-&gt;enc_open('aes-256-cbc', 'AES-256-CBC');\n$encrypted_data = openssl_encrypt($data, $cipher, $openssl-&gt;random_bytes(32), 0, '');\n$iv = substr($encrypted_data, 0, 16);\n$encrypted_data = substr($encrypted_data, 16);\n\n\/\/ &#23558;&#21152;&#23494;&#30340;&#25968;&#25454;&#20445;&#23384;&#21040;&#26032;&#30340;&#20020;&#26102;&#25991;&#20214;&#20013;\nfile_put_contents($temp_file, base64_encode($encrypted_data));\n\n\/\/ &#23558;&#20020;&#26102;&#25991;&#20214;&#31227;&#21160;&#21040;&#26032;&#20301;&#32622;\nrename($temp_file, '\/path\/to\/new\/file.enc');\n\n\/\/ &#25171;&#21360;&#21152;&#23494;&#21518;&#30340;&#25991;&#20214;&#21517;\necho \"File encrypted successfully: \" . $temp_file;\n\n\/\/ &#35299;&#23494;&#25991;&#20214;\n$decrypted_data = base64_decode(file_get_contents('\/path\/to\/new\/file.enc'));\n\n\/\/ &#23545;&#25968;&#25454;&#36827;&#34892;&#35299;&#23494;\n$cipher = $openssl-&gt;enc_open('aes-256-cbc', 'AES-256-CBC');\n$decrypted_data = openssl_decrypt($decrypted_data, $cipher, $openssl-&gt;random_bytes(32), 0, '');\n\n\/\/ &#20889;&#20837;&#21040;&#21407;&#25991;&#20214;\nfile_put_contents($file_path, $decrypted_data);\n\n\/\/ &#21024;&#38500;&#20020;&#26102;&#25991;&#20214;\nunlink($temp_file);\n?&gt;<\/code><\/pre>\n<p>&#36825;&#20010;&#20363;&#23376;&#20551;&#35774;&#20320;&#26377;&#19968;&#20010;&#21517;&#20026;<code>file.txt<\/code>&#30340;&#25991;&#26412;&#25991;&#20214;&#65292;&#20320;&#24819;&#25226;&#23427;&#21152;&#23494;&#24182;&#23384;&#20648;&#22312;&#19968;&#20010;&#21517;&#20026;<code>new-file.enc<\/code>&#30340;&#26032;&#25991;&#20214;&#20013;&#12290;&#28982;&#21518;&#65292;&#23427;&#20250;&#23581;&#35797;&#20174;&#26032;&#25991;&#20214;&#20013;&#35299;&#23494;&#20986;&#21407;&#22987;&#25968;&#25454;&#65292;&#24182;&#23558;&#23427;&#37325;&#23450;&#21521;&#22238;&#21407;&#22987;&#25991;&#20214;&#12290;&#27880;&#24847;&#65292;&#36825;&#20010;&#20363;&#23376;&#27809;&#26377;&#22788;&#29702;&#38169;&#35823;&#24773;&#20917;&#65292;&#20363;&#22914;&#22914;&#26524;&#21152;&#23494;&#36807;&#31243;&#20013;&#20986;&#29616;&#38169;&#35823;&#65292;&#25110;&#32773;&#35299;&#23494;&#21518;&#26080;&#27861;&#25214;&#21040;&#21407;&#22987;&#25968;&#25454;&#31561;&#12290;<\/p>\n<p>&#22914;&#26524;&#20320;&#38656;&#35201;&#26356;&#22797;&#26434;&#30340;&#21152;&#23494;&#21644;&#35299;&#23494;&#36807;&#31243;&#65292;&#27604;&#22914;&#20351;&#29992;&#19981;&#21516;&#30340;&#31639;&#27861;&#65288;&#22914;AES-GCM&#65289;&#65292;&#25110;&#32773;&#38656;&#35201;&#22788;&#29702;&#26356;&#22797;&#26434;&#30340;&#23433;&#20840;&#38656;&#27714;&#65288;&#22914;&#36523;&#20221;&#39564;&#35777;&#21644;&#35748;&#35777;&#65289;&#65292;&#20320;&#24212;&#35813;&#26597;&#38405;&#30456;&#20851;&#30340;&#25991;&#26723;&#21644;&#25945;&#31243;&#65292;&#22240;&#20026;&#36825;&#20123;&#21151;&#33021;&#36890;&#24120;&#37117;&#26377;&#19987;&#38376;&#30340;&#26041;&#27861;&#21644;&#24037;&#20855;&#21487;&#20197;&#25552;&#20379;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312; PHP &#20013;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;&#22810;&#31181;&#26041;&#27861;&#26469;&#21152;&#23494;&#038;#21644..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[42],"tuisongtax":[],"class_list":["post-670","my1js","type-my1js","status-publish","hentry","my1js2nav-xtywj"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=670"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=670"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=670"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}