{"id":207406,"date":"2025-07-08T13:02:48","date_gmt":"2025-07-08T05:02:48","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207406\/"},"modified":"2025-07-08T13:02:48","modified_gmt":"2025-07-08T05:02:48","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%af%86-privnote-%e4%b8%8a%e7%9a%84%e6%b6%88%e6%81%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207406\/","title":{"rendered":"\u5982\u4f55\u89e3\u5bc6 privnote \u4e0a\u7684\u6d88\u606f\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5982\u4f55\u89e3\u5bc6 privnote \u4e0a\u7684\u6d88\u606f\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-22 12:45:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u89e3\u5bc6 privnote \u4e0a\u7684\u6d88\u606f\uff1f\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5bfb\u627e\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u6765\u89e3\u5bc6 privnote.com \u7684\u6d88\u606f\uff08AJAX \u67e5\u8be2\uff09\u6211\u5c1d\u8bd5\u5c06 Python \u4e0a\u7684\u7b97\u6cd5\u91cd\u5199\u4e3a Golang\u3002 \u6211\u5728 Golang \u4e0a\u9047\u5230\u5bc6\u94a5\u5927\u5c0f\u95ee\u9898\uff1apanic: crypto\/des: invalid key size 32\u3002\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f <\/p>\n<p>P.S\uff1a\u6211\u65e0\u6cd5\u5728 SO \u4e0a\u52a0\u8f7d\u4ee3\u7801\uff08\u9519\u8bef\uff1a\u201c\u770b\u8d77\u6765\u60a8\u7684\u5e16\u5b50\u4e3b\u8981\u662f\u4ee3\u7801\uff0c\u8bf7\u6dfb\u52a0\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u201d\uff09\u3002\u5bf9\u4e0d\u8d77<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u9519\u8bef\u4e2d\u63d0\u5230\u7684\u5bc6\u94a5\u5927\u5c0f 32 \u662f\u7531 opensslkey \u51fd\u6570\u7684 return \u8bed\u53e5\u4e2d\u7684 <code>result[0 : 4*8]<\/code> \u8bbe\u7f6e\u7684\u3002<\/p>\n<pre>func opensslkey(password []byte, salt []byte) (string, string) {\n    fmt.println(\"opensslkey | password: \", password, \" | len(password): \", len(password), \" | salt: \", salt, \" | len(salt): \", len(salt))\n    pass_salt := string(password) + string(salt)\n    result := md5(pass_salt)\n    cur_hash := md5(pass_salt)\n    for i := 0; i &lt; 2; i++ {\n        cur_hash := md5(cur_hash + pass_salt)\n        result += cur_hash\n    }\n    fmt.println(\"opensslkey | result: \", result, \" len(result): \", len(result))\n    return result[0 : 4*8], result[4*8 : 4*8+16]\n}<\/pre>\n<p>\u6b64\u5bc6\u94a5\u5c06\u88ab\u4f20\u9012\u7ed9 desdecryption \u51fd\u6570\uff1a<\/p>\n<pre>dst, err_decrypt := desdecryption([]byte(key), []byte(iv), []byte(crypt_bytes))<\/pre>\n<p>\u7136\u540e\u5c06\u5176\u4f20\u9012\u7ed9 crypto\/des\uff1a<\/p>\n<pre>block, err := des.newcipher(key)\nif err != nil {\n    return nil, err\n}<\/pre>\n<p>\u5bfc\u81f4\u9519\u8bef\u7684\u539f\u56e0\u662f\u6240\u9700\u7684\u5bc6\u94a5\u5927\u5c0f\u4e3a8\uff0c\u4f46\u4f20\u9012\u4e86\u5927\u5c0f\u4e3a32\u7684\u5bc6\u94a5\u3002\u9700\u8981\u7684\u5927\u5c0f8\u662f\u901a\u8fc7\u67e5\u770b\u7684\u6e90\u4ee3\u7801\u786e\u5b9a\u7684\uff1a<\/p>\n<pre>\/\/ newcipher creates and returns a new cipher.block.\nfunc newcipher(key []byte) (cipher.block, error) {\n    if len(key) != 8 {\n        return nil, keysizeerror(len(key))\n    }\n\n    c := new(descipher)\n    c.generatesubkeys(key)\n    return c, nil\n}<\/pre>\n<p>\u60a8\u5e94\u8be5\u4f7f\u7528 \uff0c\u5b83\u5141\u8bb8\u5bc6\u94a5\u5927\u5c0f\u4e3a 32 <code>\u5bc6\u94a5\u53c2\u6570\u5e94\u8be5\u662f aes \u5bc6\u94a5\uff0c\u53ef\u4ee5\u662f 16\u300124 \u6216 32 \u5b57\u8282\u4ee5\u9009\u62e9 aes-128\u3001aes-192 \u6216 aes-256<\/code>\uff0c\u4f8b\u5982\u6b63\u5728\u4f7f\u7528\uff1a<\/p>\n<pre>pbe = openSSLkey(password, salt)\nkey = pbe[\"key\"]\niv = pbe[\"iv\"]\n\ncipher = AES.new(key, AES.MODE_CBC, iv, use_aesni=True)<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u89e3\u5bc6 privnote \u4e0a\u7684\u6d88\u606f\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207406","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207406"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207406\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}