{"id":57333,"date":"2025-03-01T10:10:55","date_gmt":"2025-03-01T02:10:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/57333\/"},"modified":"2025-03-01T10:10:55","modified_gmt":"2025-03-01T02:10:55","slug":"%e6%b7%b1%e5%85%a5%e7%90%86%e8%a7%a3shadowsocks%e4%b8%8epython%e4%b8%ad%e7%9a%84aes-256-gcm%e5%8a%a0%e5%af%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/57333\/","title":{"rendered":"\u6df1\u5165\u7406\u89e3Shadowsocks\u4e0ePython\u4e2d\u7684AES-256-GCM\u52a0\u5bc6"},"content":{"rendered":"<h2>\u5f15\u8a00<\/h2>\n<p>\u5728\u5f53\u4eca\u7f51\u7edc\u73af\u5883\u4e2d\uff0c\u5b89\u5168\u4e0e\u9690\u79c1\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\u3002<em>Shadowsocks<\/em> \u4f5c\u4e3a\u4e00\u79cd\u5b89\u5168\u4ee3\u7406\u5de5\u5177\uff0c\u4ee5\u5176\u9ad8\u6548\u7684\u52a0\u5bc6\u7b97\u6cd5\u800c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u7f51\u7edc\u73af\u5883\u3002\u7279\u522b\u662f\u5728 Python \u4e2d\u5b9e\u73b0 <em>AES-256-GCM<\/em> \u52a0\u5bc6\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u5b89\u5168\u6027\u548c\u7075\u6d3b\u6027\u3002\u672c\u6587\u5c06\u5168\u9762\u63a2\u8ba8 <em>Shadowsocks<\/em> \u7684\u5de5\u4f5c\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u5728 Python \u4e2d\u4f7f\u7528 <em>AES-256-GCM<\/em> \u52a0\u5bc6\u3002<\/p>\n<h2>\u4ec0\u4e48\u662fShadowsocks\uff1f<\/h2>\n<p><em>Shadowsocks<\/em> \u662f\u4e00\u79cd\u5f00\u6e90\u7684\u4ee3\u7406\u5de5\u5177\uff0c\u6700\u521d\u662f\u4e3a\u4e86\u89e3\u51b3\u7f51\u7edc\u5ba1\u67e5\u95ee\u9898\u800c\u5f00\u53d1\u7684\u3002\u5b83\u901a\u8fc7\u52a0\u5bc6\u6570\u636e\u6d41\u6765\u4fdd\u62a4\u7528\u6237\u9690\u79c1\uff0c\u4ece\u800c\u4f7f\u7528\u6237\u80fd\u591f\u7ed5\u8fc7\u7f51\u7edc\u9650\u5236\u3002 \u4e3b\u8981\u7279\u70b9\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd<\/strong>\uff1a\u7531\u4e8e\u5176\u9ad8\u6548\u7684\u52a0\u5bc6\u7b97\u6cd5\uff0c<em>Shadowsocks<\/em> \u80fd\u591f\u63d0\u4f9b\u4f4e\u5ef6\u8fdf\u7684\u7f51\u7edc\u4f53\u9a8c\u3002<\/li>\n<li><strong>\u8de8\u5e73\u53f0\u652f\u6301<\/strong>\uff1a<em>Shadowsocks<\/em> \u652f\u6301\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5982 Windows\u3001macOS\u3001Linux\u3001Android \u548c iOS\u3002<\/li>\n<li><strong>\u7075\u6d3b\u6027<\/strong>\uff1a\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u81ea\u5b9a\u4e49\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<h2>\u4ec0\u4e48\u662fAES-256-GCM\uff1f<\/h2>\n<p><em>AES-256-GCM<\/em> \u662f\u4e00\u79cd\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u4f7f\u7528256\u4f4d\u5bc6\u94a5\u8fdb\u884c\u52a0\u5bc6\uff0c\u5e76\u91c7\u7528 <em>Galois\/Counter Mode<\/em>\uff08GCM\uff09\u8fdb\u884c\u8ba4\u8bc1\u3002\u5176\u4e3b\u8981\u7279\u70b9\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u5b89\u5168\u6027\u9ad8<\/strong>\uff1a256\u4f4d\u5bc6\u94a5\u7684\u590d\u6742\u6027\u4f7f\u5176\u5728\u73b0\u4ee3\u8ba1\u7b97\u673a\u4e0a\u51e0\u4e4e\u4e0d\u53ef\u7834\u89e3\u3002<\/li>\n<li><strong>\u6548\u7387<\/strong>\uff1a<em>GCM<\/em> \u6a21\u5f0f\u7ed3\u5408\u4e86\u52a0\u5bc6\u548c\u8ba4\u8bc1\uff0c\u53ef\u4ee5\u5728\u4fdd\u6301\u9ad8\u6548\u7684\u540c\u65f6\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<h2>\u5728Python\u4e2d\u5b9e\u73b0AES-256-GCM<\/h2>\n<h3>1. \u5b89\u88c5\u5fc5\u8981\u7684\u5e93<\/h3>\n<p>\u8981\u5728 Python \u4e2d\u4f7f\u7528 <em>AES-256-GCM<\/em>\uff0c\u4f60\u9700\u8981\u5b89\u88c5 <code>cryptography<\/code> \u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<p>bash pip install cryptography<\/p>\n<h3>2. \u5b9e\u73b0AES-256-GCM\u52a0\u5bc6<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u5b9e\u73b0\u793a\u4f8b\uff1a<\/p>\n<p>python from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend import os<\/p>\n<p>key = os.urandom(32) # 256\u4f4d\u5bc6\u94a5 iv = os.urandom(12) # 96\u4f4dIV<\/p>\n<p>def encrypt(plaintext): cipher = Cipher(algorithms.AES(key), modes.GCM(iv), backend=default_backend()) encryptor = cipher.encryptor() ciphertext = encryptor.update(plaintext) + encryptor.finalize() return ciphertext, encryptor.tag<\/p>\n<p>def decrypt(ciphertext, tag): cipher = Cipher(algorithms.AES(key), modes.GCM(iv, tag), backend=default_backend()) decryptor = cipher.decryptor() plaintext = decryptor.update(ciphertext) + decryptor.finalize() return plaintext<\/p>\n<p>plaintext = b\u2019Hello, Shadowsocks!\u2019 ciphertext, tag = encrypt(plaintext) print(\u2018Ciphertext:\u2019, ciphertext)<\/p>\n<p>try: decrypted = decrypt(ciphertext, tag) print(\u2018Decrypted:\u2019, decrypted) except Exception as e: print(\u2018Decryption failed:\u2019, str(e))<\/p>\n<h3>3. \u4ee3\u7801\u8bf4\u660e<\/h3>\n<ul>\n<li><strong>\u5bc6\u94a5\u751f\u6210<\/strong>\uff1a\u4f7f\u7528 <code>os.urandom()<\/code> \u751f\u6210\u968f\u673a\u5bc6\u94a5\u548c\u521d\u59cb\u5316\u5411\u91cf\uff08IV\uff09\u3002<\/li>\n<li><strong>\u52a0\u5bc6\u8fc7\u7a0b<\/strong>\uff1a\u901a\u8fc7 <code>Cipher<\/code> \u7c7b\u521b\u5efa\u52a0\u5bc6\u5bf9\u8c61\uff0c\u4f7f\u7528 <em>AES-256-GCM<\/em> \u6a21\u5f0f\u8fdb\u884c\u52a0\u5bc6\u3002<\/li>\n<li><strong>\u89e3\u5bc6\u8fc7\u7a0b<\/strong>\uff1a\u76f8\u5e94\u5730\uff0c\u521b\u5efa\u89e3\u5bc6\u5bf9\u8c61\uff0c\u4f7f\u7528\u76f8\u540c\u7684\u5bc6\u94a5\u548cIV\u8fdb\u884c\u89e3\u5bc6\u3002<\/li>\n<\/ul>\n<h2>Shadowsocks\u4e2d\u7684AES-256-GCM\u5e94\u7528<\/h2>\n<p>\u5728 <em>Shadowsocks<\/em> \u4e2d\uff0c<em>AES-256-GCM<\/em> \u4e3b\u8981\u7528\u4e8e\u52a0\u5bc6\u7528\u6237\u6570\u636e\u6d41\uff0c\u4ece\u800c\u786e\u4fdd\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u7684\u5b89\u5168\u6027\u3002\u5176\u5e94\u7528\u4f18\u52bf\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u964d\u4f4e\u5ef6\u8fdf<\/strong>\uff1a\u7531\u4e8e <em>AES-256-GCM<\/em> \u7684\u9ad8\u6548\u6027\u80fd\uff0c\u6570\u636e\u5728\u52a0\u5bc6\u548c\u89e3\u5bc6\u8fc7\u7a0b\u4e2d\u51e0\u4e4e\u4e0d\u4f1a\u4ea7\u751f\u663e\u8457\u5ef6\u8fdf\u3002<\/li>\n<li><strong>\u9632\u6b62\u6570\u636e\u7be1\u6539<\/strong>\uff1a<em>GCM<\/em> \u6a21\u5f0f\u63d0\u4f9b\u4e86\u6570\u636e\u5b8c\u6574\u6027\u9a8c\u8bc1\uff0c\u53ef\u4ee5\u68c0\u6d4b\u6570\u636e\u662f\u5426\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u7be1\u6539\u3002<\/li>\n<\/ul>\n<h2>\u4f7f\u7528Shadowsocks\u4e0eAES-256-GCM\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n<ul>\n<li><strong>\u9009\u62e9\u5408\u9002\u7684\u5bc6\u94a5<\/strong>\uff1a\u786e\u4fdd\u4f7f\u7528\u8db3\u591f\u590d\u6742\u7684\u5bc6\u94a5\uff0c\u4ee5\u589e\u52a0\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u5b9a\u671f\u66f4\u6362\u5bc6\u94a5<\/strong>\uff1a\u5b9a\u671f\u66f4\u65b0\u5bc6\u94a5\u53ef\u4ee5\u6709\u6548\u63d0\u9ad8\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u4fdd\u62a4\u79c1\u94a5<\/strong>\uff1a\u5bc6\u94a5\u7684\u5b89\u5168\u6027\u662f\u786e\u4fdd\u6570\u636e\u5b89\u5168\u7684\u5173\u952e\u3002<\/li>\n<\/ul>\n<h2>FAQ<\/h2>\n<h3>1. Shadowsocks\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f<\/h3>\n<p><em>Shadowsocks<\/em> \u901a\u8fc7\u5728\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u5efa\u7acb\u52a0\u5bc6\u96a7\u9053\uff0c\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u5b89\u5168\u5730\u8bbf\u95ee\u88ab\u9650\u5236\u7684\u5185\u5bb9\u3002\u5b83\u4f7f\u7528\u9ad8\u6548\u7684\u52a0\u5bc6\u7b97\u6cd5\u5c06\u6570\u636e\u8fdb\u884c\u52a0\u5bc6\uff0c\u4ece\u800c\u786e\u4fdd\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u4e0d\u88ab\u76d1\u542c\u6216\u7be1\u6539\u3002<\/p>\n<h3>2. AES-256-GCM\u7684\u5b89\u5168\u6027\u5982\u4f55\uff1f<\/h3>\n<p><em>AES-256-GCM<\/em> \u88ab\u8ba4\u4e3a\u662f\u975e\u5e38\u5b89\u5168\u7684\uff0c\u52a0\u5bc6\u5f3a\u5ea6\u5728\u76ee\u524d\u7684\u8ba1\u7b97\u673a\u6280\u672f\u4e0b\u51e0\u4e4e\u4e0d\u53ef\u7834\u89e3\u3002\u5176\u4f7f\u7528\u7684256\u4f4d\u5bc6\u94a5\u63d0\u4f9b\u4e86\u6781\u9ad8\u7684\u5b89\u5168\u6027\uff0c\u5e76\u4e14 <em>GCM<\/em> \u6a21\u5f0f\u4fdd\u8bc1\u4e86\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/p>\n<h3>3. \u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528Shadowsocks\uff1f<\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5 <code>shadowsocks<\/code> \u5e93\u5e76\u914d\u7f6e\u76f8\u5e94\u7684\u670d\u52a1\u5668\u5730\u5740\u548c\u7aef\u53e3\u8fdb\u884c\u4f7f\u7528\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5b89\u88c5\u5e93\uff1a<code>pip install shadowsocks<\/code><\/li>\n<li>\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u670d\u52a1\u5668\u5730\u5740\u3001\u7aef\u53e3\u548c\u52a0\u5bc6\u65b9\u6cd5\uff08\u5982 <em>AES-256-GCM<\/em>\uff09\u3002<\/li>\n<\/ul>\n<h3>4. Shadowsocks\u652f\u6301\u54ea\u4e9b\u52a0\u5bc6\u65b9\u5f0f\uff1f<\/h3>\n<p><em>Shadowsocks<\/em> \u652f\u6301\u591a\u79cd\u52a0\u5bc6\u65b9\u5f0f\uff0c\u5305\u62ec <em>AES-128-CFB<\/em>\u3001<em>AES-256-CFB<\/em>\u3001<em>Chacha20<\/em> \u7b49\uff0c\u5176\u4e2d <em>AES-256-GCM<\/em> \u662f\u63a8\u8350\u7684\u5b89\u5168\u9009\u9879\u3002<\/p>\n<h2>\u7ed3\u8bba<\/h2>\n<p><em>Shadowsocks<\/em> \u7ed3\u5408 <em>AES-256-GCM<\/em> \u52a0\u5bc6\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u6548\u3001\u5b89\u5168\u7684\u7f51\u7edc\u4ee3\u7406\u5de5\u5177\u3002\u5728\u5b9e\u73b0\u8fc7\u7a0b\u4e2d\uff0cPython \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u652f\u6301\uff0c\u4f7f\u5f97\u7528\u6237\u80fd\u591f\u7075\u6d3b\u5730\u914d\u7f6e\u548c\u4f7f\u7528\u3002\u901a\u8fc7\u4e86\u89e3 <em>Shadowsocks<\/em> \u548c <em>AES-256-GCM<\/em> \u7684\u5de5\u4f5c\u539f\u7406\uff0c\u7528\u6237\u80fd\u591f\u66f4\u597d\u5730\u4fdd\u62a4\u4ed6\u4eec\u7684\u7f51\u7edc\u5b89\u5168\u4e0e\u9690\u79c1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00 \u5728\u5f53\u4eca\u7f51\u7edc\u73af\u5883\u4e2d\uff0c\u5b89\u5168\u4e0e\u9690\u79c1\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\u3002Shadowsocks \u4f5c\u4e3a\u4e00\u79cd\u5b89\u5168\u4ee3\u7406\u5de5\u5177\uff0c\u4ee5\u5176\u9ad8\u6548\u7684\u52a0\u5bc6\u7b97\u6cd5\u800c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u7f51\u7edc\u73af\u5883\u3002\u7279\u522b\u662f\u5728 Python \u4e2d\u5b9e\u73b0 AES-256-GCM \u52a0\u5bc6\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u5b89\u5168\u6027\u548c\u7075\u6d3b\u6027\u3002\u672c\u6587\u5c06\u5168\u9762\u63a2\u8ba8 Shadowsocks \u7684\u5de5\u4f5c\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u5728 Python \u4e2d\u4f7f\u7528 AES-256-GCM \u52a0\u5bc6\u3002 \u4ec0\u4e48\u662fShadowsocks\uff1f Shadowsocks \u662f\u4e00\u79cd\u5f00\u6e90\u7684\u4ee3\u7406\u5de5\u5177\uff0c\u6700\u521d\u662f\u4e3a\u4e86\u89e3\u51b3\u7f51\u7edc\u5ba1\u67e5\u95ee\u9898\u800c\u5f00\u53d1\u7684\u3002\u5b83\u901a\u8fc7\u52a0\u5bc6\u6570\u636e\u6d41\u6765\u4fdd\u62a4\u7528\u6237\u9690\u79c1\uff0c\u4ece\u800c\u4f7f\u7528\u6237\u80fd\u591f\u7ed5\u8fc7\u7f51\u7edc\u9650\u5236\u3002 \u4e3b\u8981\u7279\u70b9\u5305\u62ec\uff1a \u9ad8\u6027\u80fd\uff1a\u7531\u4e8e\u5176\u9ad8\u6548\u7684\u52a0\u5bc6\u7b97\u6cd5\uff0cShadowsocks \u80fd\u591f\u63d0\u4f9b\u4f4e\u5ef6\u8fdf\u7684\u7f51\u7edc\u4f53\u9a8c\u3002 \u8de8\u5e73\u53f0\u652f\u6301\uff1aShadowsocks \u652f\u6301\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5982 Windows\u3001macOS\u3001Linux\u3001Android \u548c iOS\u3002 \u7075\u6d3b\u6027\uff1a\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u81ea\u5b9a\u4e49\u914d\u7f6e\u3002 \u4ec0\u4e48\u662fAES-256-GCM\uff1f AES-256-GCM \u662f\u4e00\u79cd\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u4f7f\u7528256\u4f4d\u5bc6\u94a5\u8fdb\u884c\u52a0\u5bc6\uff0c\u5e76\u91c7\u7528 Galois\/Counter Mode\uff08GCM\uff09\u8fdb\u884c\u8ba4\u8bc1\u3002\u5176\u4e3b\u8981\u7279\u70b9\u5305\u62ec\uff1a \u5b89\u5168\u6027\u9ad8\uff1a256\u4f4d\u5bc6\u94a5\u7684\u590d\u6742\u6027\u4f7f\u5176\u5728\u73b0\u4ee3\u8ba1\u7b97\u673a\u4e0a\u51e0\u4e4e\u4e0d\u53ef\u7834\u89e3\u3002 \u6548\u7387\uff1aGCM \u6a21\u5f0f\u7ed3\u5408\u4e86\u52a0\u5bc6\u548c\u8ba4\u8bc1\uff0c\u53ef\u4ee5\u5728\u4fdd\u6301\u9ad8\u6548\u7684\u540c\u65f6\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002 \u5728Python\u4e2d\u5b9e\u73b0AES-256-GCM 1. \u5b89\u88c5\u5fc5\u8981\u7684\u5e93 \u8981\u5728 Python \u4e2d\u4f7f\u7528 AES-256-GCM\uff0c\u4f60\u9700\u8981\u5b89\u88c5 cryptography \u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a bash pip install cryptography 2. \u5b9e\u73b0AES-256-GCM\u52a0\u5bc6 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u5b9e\u73b0\u793a\u4f8b\uff1a python from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-57333","post","type-post","status-publish","format-standard","hentry","category-vpn"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/57333","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=57333"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/57333\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=57333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=57333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=57333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}