{"id":62254,"date":"2025-04-29T09:16:16","date_gmt":"2025-04-29T01:16:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/62254\/"},"modified":"2025-04-29T09:16:16","modified_gmt":"2025-04-29T01:16:16","slug":"%e9%ba%92%e9%ba%9f%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e6%96%87%e4%bb%b6%e5%8a%a0%e5%af%86%e5%92%8c%e8%a7%a3%e5%af%86%e5%a6%82%e4%bd%95%e4%bf%9d%e6%8a%a4%e4%bd%a0%e7%9a%84%e9%9a%90-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/62254\/","title":{"rendered":"\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u5982\u4f55\u4fdd\u62a4\u4f60\u7684\u9690\u79c1\uff1f"},"content":{"rendered":"<p>\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u5982\u4f55\u4fdd\u62a4\u4f60\u7684\u9690\u79c1\uff1f<\/p>\n<p>\u968f\u7740\u4fe1\u606f\u6280\u672f\u7684\u53d1\u5c55\uff0c\u6211\u4eec\u7684\u79c1\u4eba\u4fe1\u606f\u8d8a\u6765\u8d8a\u5bb9\u6613\u53d7\u5230\u6cc4\u9732\u548c\u4fb5\u72af\u3002\u4e3a\u4e86\u4fdd\u62a4\u6211\u4eec\u7684\u9690\u79c1\uff0c\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u6210\u4e3a\u4e86\u4e00\u79cd\u5e38\u7528\u7684\u624b\u6bb5\u3002\u5728\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u5176\u63d0\u4f9b\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u529f\u80fd\u6765\u4fdd\u62a4\u81ea\u5df1\u7684\u9690\u79c1\u548c\u654f\u611f\u6570\u636e\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u529f\u80fd\uff0c\u5e76\u7ed9\u51fa\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u63a5\u53e3\u3002\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u4e86\u4e00\u5957\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u5e93\uff0c\u5305\u542b\u4e86\u5e38\u7528\u7684\u52a0\u5bc6\u7b97\u6cd5\u548c\u89e3\u5bc6\u7b97\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u8fd9\u4e9b\u5e93\u4e2d\u7684\u51fd\u6570\u6765\u5b9e\u73b0\u6587\u4ef6\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u5bc6\u51fd\u6570\u793a\u4f8b\uff1a<\/p>\n<pre>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;string.h&gt;\n#include &lt;openssl&gt;\n\nvoid encrypt_file(const char *input_file, const char *output_file, const char *key) {\n    EVP_CIPHER_CTX *ctx;\n    FILE *input, *output;\n    unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];\n    int outlen, len, total = 0;\n\n    \/\/ \u521d\u59cb\u5316\u52a0\u5bc6\u73af\u5883\n    ctx = EVP_CIPHER_CTX_new();\n    EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, NULL);\n\n    \/\/ \u6253\u5f00\u8f93\u5165\u6587\u4ef6\n    input = fopen(input_file, \"rb\");\n    if (!input) {\n        fprintf(stderr, \"Failed to open input file: %s\n\", input_file);\n        return;\n    }\n\n    \/\/ \u6253\u5f00\u8f93\u51fa\u6587\u4ef6\n    output = fopen(output_file, \"wb\");\n    if (!output) {\n        fprintf(stderr, \"Failed to open output file: %s\n\", output_file);\n        fclose(input);\n        return;\n    }\n\n    \/\/ \u9010\u5757\u52a0\u5bc6\u6570\u636e\n    while ((len = fread(inbuf, 1, sizeof(inbuf), input)) &amp;gt; 0) {\n        EVP_EncryptUpdate(ctx, outbuf, &amp;amp;outlen, inbuf, len);\n        fwrite(outbuf, 1, outlen, output);\n        total += outlen;\n    }\n\n    \/\/ \u7ed3\u675f\u52a0\u5bc6\u8fc7\u7a0b\n    EVP_EncryptFinal_ex(ctx, outbuf, &amp;amp;outlen);\n    fwrite(outbuf, 1, outlen, output);\n    total += outlen;\n\n    \/\/ \u6e05\u7406\u5de5\u4f5c\n    fclose(input);\n    fclose(output);\n    EVP_CIPHER_CTX_free(ctx);\n\n    printf(\"Encryption finished. Encrypted %d bytes.\n\", total);\n}\n\nint main() {\n    const char *input_file = \"plain.txt\";\n    const char *output_file = \"encrypted.txt\";\n    const char *key = \"abcdefghijklmnop\";  \/\/ 16\u5b57\u8282\u7684\u5bc6\u94a5\n\n    encrypt_file(input_file, output_file, key);\n\n    return 0;\n}&lt;\/openssl&gt;&lt;\/string.h&gt;&lt;\/stdlib.h&gt;&lt;\/stdio.h&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u63a5\u53e3\u5c06\u4e00\u4e2a\u6587\u4ef6\u52a0\u5bc6\u6210\u53e6\u4e00\u4e2a\u6587\u4ef6\u3002\u6211\u4eec\u9996\u5148\u9700\u8981\u6253\u5f00\u8f93\u5165\u6587\u4ef6\u548c\u8f93\u51fa\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528\u6307\u5b9a\u7684\u5bc6\u94a5\u5bf9\u8f93\u5165\u6587\u4ef6\u8fdb\u884c\u52a0\u5bc6\uff0c\u5e76\u5c06\u7ed3\u679c\u5199\u5165\u8f93\u51fa\u6587\u4ef6\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u6e05\u7406\u76f8\u5173\u8d44\u6e90\uff0c\u5e76\u8f93\u51fa\u52a0\u5bc6\u7684\u603b\u5b57\u8282\u6570\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5bc6\u94a5\u7684\u957f\u5ea6\u9700\u8981\u6ee1\u8db3\u52a0\u5bc6\u7b97\u6cd5\u7684\u8981\u6c42\u3002<\/p>\n<p>\u9664\u4e86\u6587\u4ef6\u52a0\u5bc6\uff0c\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u8fd8\u63d0\u4f9b\u4e86\u6587\u4ef6\u89e3\u5bc6\u7684\u529f\u80fd\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u89e3\u5bc6\u51fd\u6570\u793a\u4f8b\uff1a<\/p>\n<pre>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;string.h&gt;\n#include &lt;openssl&gt;\n\nvoid decrypt_file(const char *input_file, const char *output_file, const char *key) {\n    EVP_CIPHER_CTX *ctx;\n    FILE *input, *output;\n    unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];\n    int outlen, len, total = 0;\n\n    \/\/ \u521d\u59cb\u5316\u89e3\u5bc6\u73af\u5883\n    ctx = EVP_CIPHER_CTX_new();\n    EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, NULL);\n\n    \/\/ \u6253\u5f00\u8f93\u5165\u6587\u4ef6\n    input = fopen(input_file, \"rb\");\n    if (!input) {\n        fprintf(stderr, \"Failed to open input file: %s\n\", input_file);\n        return;\n    }\n\n    \/\/ \u6253\u5f00\u8f93\u51fa\u6587\u4ef6\n    output = fopen(output_file, \"wb\");\n    if (!output) {\n        fprintf(stderr, \"Failed to open output file: %s\n\", output_file);\n        fclose(input);\n        return;\n    }\n\n    \/\/ \u9010\u5757\u89e3\u5bc6\u6570\u636e\n    while ((len = fread(inbuf, 1, sizeof(inbuf), input)) &amp;gt; 0) {\n        EVP_DecryptUpdate(ctx, outbuf, &amp;amp;outlen, inbuf, len);\n        fwrite(outbuf, 1, outlen, output);\n        total += outlen;\n    }\n\n    \/\/ \u7ed3\u675f\u89e3\u5bc6\u8fc7\u7a0b\n    EVP_DecryptFinal_ex(ctx, outbuf, &amp;amp;outlen);\n    fwrite(outbuf, 1, outlen, output);\n    total += outlen;\n\n    \/\/ \u6e05\u7406\u5de5\u4f5c\n    fclose(input);\n    fclose(output);\n    EVP_CIPHER_CTX_free(ctx);\n\n    printf(\"Decryption finished. Decrypted %d bytes.\n\", total);\n}\n\nint main() {\n    const char *input_file = \"encrypted.txt\";\n    const char *output_file = \"plain.txt\";\n    const char *key = \"abcdefghijklmnop\";  \/\/ 16\u5b57\u8282\u7684\u5bc6\u94a5\n\n    decrypt_file(input_file, output_file, key);\n\n    return 0;\n}&lt;\/openssl&gt;&lt;\/string.h&gt;&lt;\/stdlib.h&gt;&lt;\/stdio.h&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u89e3\u5bc6\u63a5\u53e3\u5c06\u4e00\u4e2a\u52a0\u5bc6\u7684\u6587\u4ef6\u89e3\u5bc6\u6210\u539f\u59cb\u6587\u4ef6\u3002\u6211\u4eec\u9996\u5148\u9700\u8981\u6253\u5f00\u8f93\u5165\u6587\u4ef6\u548c\u8f93\u51fa\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528\u6307\u5b9a\u7684\u5bc6\u94a5\u5bf9\u8f93\u5165\u6587\u4ef6\u8fdb\u884c\u89e3\u5bc6\uff0c\u5e76\u5c06\u7ed3\u679c\u5199\u5165\u8f93\u51fa\u6587\u4ef6\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u6e05\u7406\u76f8\u5173\u8d44\u6e90\uff0c\u5e76\u8f93\u51fa\u89e3\u5bc6\u7684\u603b\u5b57\u8282\u6570\u3002<\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u793a\u4f8b\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u4f7f\u7528\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u529f\u80fd\u6765\u4fdd\u62a4\u6211\u4eec\u7684\u9690\u79c1\u548c\u654f\u611f\u6570\u636e\u3002\u8bf7\u6ce8\u610f\uff0c\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6ce8\u610f\u5bc6\u94a5\u7684\u751f\u6210\u3001\u5b58\u50a8\u548c\u7ba1\u7406\uff0c\u4ee5\u53ca\u52a0\u5bc6\u7b97\u6cd5\u7684\u9009\u62e9\u548c\u53c2\u6570\u8bbe\u7f6e\uff0c\u6765\u63d0\u9ad8\u6587\u4ef6\u52a0\u5bc6\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p>\u603b\u800c\u8a00\u4e4b\uff0c\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u529f\u80fd\u4e3a\u6211\u4eec\u4fdd\u62a4\u9690\u79c1\u63d0\u4f9b\u4e86\u65b9\u4fbf\u548c\u53ef\u9760\u7684\u624b\u6bb5\u3002\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u548c\u5b9e\u9645\u60c5\u51b5\uff0c\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u529f\u80fd\u6765\u52a0\u5f3a\u5bf9\u654f\u611f\u6570\u636e\u7684\u4fdd\u62a4\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u5982\u4f55\u4fdd\u62a4\u4f60\u7684\u9690\u79c1\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u5982\u4f55\u4fdd\u62a4\u4f60\u7684\u9690\u79c1\uff1f \u968f\u7740\u4fe1\u606f\u6280\u672f\u7684\u53d1\u5c55\uff0c\u6211\u4eec\u7684\u79c1\u4eba\u4fe1\u606f\u8d8a\u6765\u8d8a\u5bb9\u6613\u53d7\u5230\u6cc4\u9732\u548c\u4fb5\u72af\u3002\u4e3a\u4e86\u4fdd\u62a4\u6211\u4eec\u7684\u9690\u79c1\uff0c\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u6210\u4e3a\u4e86\u4e00\u79cd\u5e38\u7528\u7684\u624b\u6bb5\u3002\u5728\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u5176\u63d0\u4f9b\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u529f\u80fd\u6765\u4fdd\u62a4\u81ea\u5df1\u7684\u9690\u79c1\u548c\u654f\u611f\u6570\u636e\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u529f\u80fd\uff0c\u5e76\u7ed9\u51fa\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u63a5\u53e3\u3002\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u4e86\u4e00\u5957\u6587\u4ef6\u52a0\u5bc6\u548c\u89e3\u5bc6\u5e93\uff0c\u5305\u542b\u4e86\u5e38\u7528\u7684\u52a0\u5bc6\u7b97\u6cd5\u548c\u89e3\u5bc6\u7b97\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u8fd9\u4e9b\u5e93\u4e2d\u7684\u51fd\u6570\u6765\u5b9e\u73b0\u6587\u4ef6\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u5bc6\u51fd\u6570\u793a\u4f8b\uff1a #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;openssl&gt; void encrypt_file(const char *input_file, const char *output_file, const char *key) { EVP_CIPHER_CTX *ctx; FILE *input, *output; unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; int outlen, len, total = 0; \/\/ \u521d\u59cb\u5316\u52a0\u5bc6\u73af\u5883 ctx = EVP_CIPHER_CTX_new(); EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, NULL); \/\/ \u6253\u5f00\u8f93\u5165\u6587\u4ef6 input = fopen(input_file, &#8220;rb&#8221;); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-62254","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=62254"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62254\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=62254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=62254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=62254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}