{"id":1380,"date":"2026-01-17T10:17:58","date_gmt":"2026-01-17T02:17:58","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=1380"},"modified":"2026-01-17T10:17:58","modified_gmt":"2026-01-17T02:17:58","slug":"sha1%e5%8a%a0%e5%af%86","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/01\/17\/sha1%e5%8a%a0%e5%af%86\/","title":{"rendered":"sha1\u52a0\u5bc6"},"content":{"rendered":"\n<p>\u660e\u767d\u4e86\uff0c\u4f60\u662f\u60f3\u4e86\u89e3 <strong>SHA-1 \u52a0\u5bc6<\/strong>\uff08\u4e25\u683c\u6765\u8bf4\u662f\u54c8\u5e0c\uff0c\u4e0d\u662f\u52a0\u5bc6\uff09\u3002\u6211\u7ed9\u4f60\u505a\u4e00\u4e2a <strong>\u5168\u9762\u8bb2\u89e3<\/strong>\uff0c\u5305\u62ec\u539f\u7406\u3001\u7279\u70b9\u3001\u4f7f\u7528\u65b9\u6cd5\u548c Python \u793a\u4f8b\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1\ufe0f\u20e3 SHA-1 \u662f\u4ec0\u4e48<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SHA-1\uff08Secure Hash Algorithm 1\uff09<\/strong> \u662f\u4e00\u79cd <strong>\u54c8\u5e0c\u7b97\u6cd5<\/strong><\/li>\n\n\n\n<li>\u8f93\u5165\u4efb\u610f\u957f\u5ea6\u7684\u6570\u636e \u2192 \u8f93\u51fa <strong>\u56fa\u5b9a 160 \u4f4d\uff0820 \u5b57\u8282\uff09\u6458\u8981<\/strong><\/li>\n\n\n\n<li>\u5e38\u7528\u4e8e\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6570\u636e\u5b8c\u6574\u6027\u6821\u9a8c\uff08\u5982 Git \u63d0\u4ea4 hash\uff09<\/li>\n\n\n\n<li>\u6587\u4ef6\u6821\u9a8c<\/li>\n\n\n\n<li>\u751f\u6210\u7b7e\u540d\u6458\u8981<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6ce8\u610f\uff1aSHA-1 <strong>\u4e0d\u662f\u53ef\u9006\u7684\u52a0\u5bc6<\/strong>\uff0c\u4e0d\u80fd\u89e3\u5bc6\u56de\u539f\u6587\uff0c\u53ea\u80fd\u6bd4\u5bf9\u54c8\u5e0c\u503c\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2\ufe0f\u20e3 SHA-1 \u7279\u70b9<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7279\u6027<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>\u8f93\u51fa\u957f\u5ea6<\/td><td>160 \u4f4d\uff0820 \u5b57\u8282\uff09\uff0c\u4e00\u822c\u7528 40 \u4f4d\u5341\u516d\u8fdb\u5236\u8868\u793a<\/td><\/tr><tr><td>\u5355\u5411\u6027<\/td><td>\u7ed9\u5b9a\u6458\u8981\u65e0\u6cd5\u63a8\u7b97\u539f\u59cb\u6570\u636e<\/td><\/tr><tr><td>\u654f\u611f\u6027<\/td><td>\u539f\u6587\u54ea\u6015\u6539\u52a8\u4e00\u4e2a\u5b57\u8282\uff0c\u6458\u8981\u5b8c\u5168\u4e0d\u540c<\/td><\/tr><tr><td>\u5b89\u5168\u6027<\/td><td>\u5df2\u88ab\u7834\u89e3\uff08\u53ef\u4ea7\u751f\u78b0\u649e\uff09\uff0c\u4e0d\u63a8\u8350\u7528\u4e8e\u5bc6\u7801\u5b58\u50a8<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2705 \u53ef\u4ee5\u7528\u4f5c\u6587\u4ef6\u6821\u9a8c\u3001\u6570\u5b57\u7b7e\u540d\u7b49<br>\u274c \u4e0d\u63a8\u8350\u7528\u4e8e\u5bc6\u7801\u52a0\u5bc6\u6216\u5b89\u5168\u8ba4\u8bc1\uff08\u6539\u7528 SHA-256 \u6216 SHA-3\uff09<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3\ufe0f\u20e3 SHA-1 Python \u793a\u4f8b<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport hashlib\n\n# \u539f\u59cb\u5b57\u7b26\u4e32\ntext = &quot;Hello, world!&quot;\n\n# \u521b\u5efa SHA-1 \u5bf9\u8c61\nsha1 = hashlib.sha1()\n\n# \u66f4\u65b0\u6570\u636e\uff08\u5fc5\u987b\u662f bytes \u7c7b\u578b\uff09\nsha1.update(text.encode(&#039;utf-8&#039;))\n\n# \u83b7\u53d6\u5341\u516d\u8fdb\u5236\u6458\u8981\nhash_result = sha1.hexdigest()\n\nprint(&quot;\u539f\u6587:&quot;, text)\nprint(&quot;SHA-1 \u54c8\u5e0c:&quot;, hash_result)\n\n<\/pre><\/div>\n\n\n<p>\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\u539f\u6587: Hello, world!\nSHA-1 \u54c8\u5e0c: 943a702d06f34599aee1f8da8ef9f7296031d699\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 \u4e00\u884c\u751f\u6210<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nhashlib.sha1(&quot;Hello, world!&quot;.encode(&#039;utf-8&#039;)).hexdigest()\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4\ufe0f\u20e3 \u6587\u4ef6 SHA-1 \u6821\u9a8c\u793a\u4f8b<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport hashlib\n\ndef file_sha1(filename):\n    sha1 = hashlib.sha1()\n    with open(filename, &#039;rb&#039;) as f:\n        while True:\n            data = f.read(65536)  # \u5206\u5757\u8bfb\u53d6\n            if not data:\n                break\n            sha1.update(data)\n    return sha1.hexdigest()\n\nprint(file_sha1(&quot;example.zip&quot;))\n\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5206\u5757\u8bfb\u53d6\u5927\u6587\u4ef6\uff0c\u907f\u514d\u4e00\u6b21\u6027\u8bfb\u5165\u5185\u5b58\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5\ufe0f\u20e3 \u5b89\u5168\u6027\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SHA-1 <strong>\u5df2\u7ecf\u4e0d\u5b89\u5168<\/strong>\uff0c\u5b58\u5728\u78b0\u649e\u653b\u51fb<\/li>\n\n\n\n<li>\u5bf9\u5bc6\u7801\u7b49\u654f\u611f\u4fe1\u606f\uff0c\u5e94\u4f7f\u7528\uff1a\n<ul class=\"wp-block-list\">\n<li><code>SHA-256 \/ SHA-512<\/code><\/li>\n\n\n\n<li>\u6216\u66f4\u5b89\u5168\u7684 <code>bcrypt \/ scrypt \/ Argon2<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>SHA-1 \u9002\u5408\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6587\u4ef6\u6821\u9a8c<\/li>\n\n\n\n<li>Git \u54c8\u5e0c<\/li>\n\n\n\n<li>\u7b80\u5355\u7b7e\u540d\u6458\u8981\uff08\u975e\u5b89\u5168\u5173\u952e\u573a\u666f\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u660e\u767d\u4e86\uff0c\u4f60\u662f\u60f3\u4e86\u89e3 SHA-1 \u52a0\u5bc6\uff08\u4e25\u683c\u6765\u8bf4\u662f\u54c8\u5e0c\uff0c\u4e0d\u662f\u52a0\u5bc6\uff09\u3002\u6211\u7ed9\u4f60\u505a\u4e00\u4e2a &#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2026\/01\/17\/sha1%e5%8a%a0%e5%af%86\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-1380","post","type-post","status-publish","format-standard","hentry","category-12"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=1380"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1380\/revisions"}],"predecessor-version":[{"id":1381,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1380\/revisions\/1381"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=1380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=1380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=1380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}