區(qū)塊鏈中的密碼學之hash算法(一)

<section class="xmt-style-block" data-style-type="1" data-tools="新媒體排版" data-id="12991"><section class="KolEditor" style="border-width: 0px;border-style: none;border-color: initial;padding: 0px;"><section style="text-align: center;margin-top:20px;"><section style="display: inline-block;width:20%;margin-right: -16px;"><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span></section><section class="title active" style="display: inline-block;padding: 3px 15px;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);color: rgb(28, 95, 195);font-size: 16px;font-weight: bold;vertical-align: middle;border-radius: 20px;"><p style="min-width: 1em;color:rgb(28,95,195);font-size: 16px;font-weight:bold;">前言</p></section><section style="display: inline-block;width:20%;margin-left: -16px;"><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span></section></section></section></section><p>????????</p><p>????????Hash算法我們可能早就聽過庙睡,不僅僅應用在密碼學領域寝受。由于hash算法所體現的思想十分的滿足我們的需求,比如可以把一個十分復雜的東西映射到另外一個較為簡單的地方墙牌,所以很多地方都有應用轩娶。</p><p>????????????????<br /></p><section class="xmt-style-block" data-style-type="1" data-tools="新媒體排版" data-id="12991"><section class="KolEditor" style="border-width: 0px;border-style: none;border-color: initial;padding: 0px;"><section style="text-align: center;margin-top:20px;"><section style="display: inline-block;width:20%;margin-right: -16px;"><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span></section><section class="title active" style="display: inline-block;padding: 3px 15px;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);color: rgb(28, 95, 195);font-size: 16px;font-weight: bold;vertical-align: middle;border-radius: 20px;"><p style="min-width: 1em;color:rgb(28,95,195);font-size: 16px;font-weight:bold;">1. 什么是hash算法疑务?</p></section><section style="display: inline-block;width:20%;margin-left: -16px;"><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span></section></section></section></section><p>? ?</p><p>????????Hash(哈险雌啵或散列,<span style="font-size: 15px;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);">Hash Algorithm</span>)算法是信息技術領域非持剩基礎也非常重要的技術撒蟀。它能任意長度的二進制值(明文)映射為較短的固定長度的二進制值(Hash值),并且不同的明文很難映射為相同的Hash值温鸽。?</p><p><br /></p><p><span style="font-family: -apple-system-font, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;">? ? </span><span style="font-family: -apple-system-font, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;">? ?</span><span style="font-family: -apple-system-font, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;">Hash算法的核心思想:<strong>基于內容進行編址或者命名</strong>保屯。?</span></p><p><br /></p><section class="xmt-style-block" data-style-type="1" data-tools="新媒體排版" data-id="12991"><section class="KolEditor" style="border-width: 0px;border-style: none;border-color: initial;padding: 0px;"><section style="text-align: center;margin-top:20px;"><section style="display: inline-block;width:20%;margin-right: -16px;"><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span></section><section class="title active" style="display: inline-block;padding: 3px 15px;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);color: rgb(28, 95, 195);font-size: 16px;font-weight: bold;vertical-align: middle;border-radius: 20px;"><p style="min-width: 1em;color:rgb(28,95,195);font-size: 16px;font-weight:bold;">2. Hash算法的特點</p></section><section style="display: inline-block;width:20%;margin-left: -16px;"><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span></section></section></section></section><p><br /></p><p><span style="letter-spacing: 0.544px;background-color: rgb(255, 255, 255);font-size: 17px;">一個優(yōu)秀的 hash 算法,將能實現:</span></p><p><span style="font-size: 15px;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);"><br /></span></p><ul class=" list-paddingleft-2" style="list-style-type: circle;"><li><p>正向快速:給定明文和hash算法涤垫,在有限時間和有限資源內能計算出hash值姑尺。</p><p><br /></p></li><li><p>逆向困難:給定(若干)hash值,在有限時間內很難(基本不可能)逆推出明文蝠猬。</p></li></ul><p><br /></p><ul class=" list-paddingleft-2" style="list-style-type: circle;"><li><p>輸入敏感:原始輸入信息修改一點信息切蟋,產生的hash值看起來應該都有很大不同。</p></li></ul><p><br /></p><ul class=" list-paddingleft-2" style="list-style-type: circle;"><li><p>沖突避免:很難找到兩段內容不同的明文榆芦,使得它們的hash值一致(發(fā)生沖突)柄粹。?</p></li></ul><p><span style="font-size: 15px;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);"><br /></span><br /></p><p>????????如果給定一個明文前提下,難以找到碰撞的另一個明文匆绣,稱為“<strong>弱抗碰撞性</strong>”驻右;如果難以找到任意兩個明文,發(fā)生碰撞崎淳,則稱算法具有“<strong>強抗碰撞性</strong>”堪夭。?</p><p><br /></p><p><br /></p><section class="xmt-style-block" data-style-type="1" data-tools="新媒體排版" data-id="12991"><section class="KolEditor" style="border-width: 0px;border-style: none;border-color: initial;padding: 0px;"><section style="text-align: center;margin-top:20px;"><section style="display: inline-block;width:20%;margin-right: -16px;"><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span></section><section class="title active" style="display: inline-block;padding: 3px 15px;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);color: rgb(28, 95, 195);font-size: 16px;font-weight: bold;vertical-align: middle;border-radius: 20px;"><p style="min-width: 1em;color:rgb(28,95,195);font-size: 16px;font-weight:bold;">3. 流行的hash算法</p></section><section style="display: inline-block;width:20%;margin-left: -16px;"><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span></section></section></section></section><p><br /></p><p style="margin-bottom: 15px;max-width: 100%;min-height: 1em;font-size: 16px;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">? ? </span><span style="max-width: 100%;font-size: 17px;box-sizing: border-box !important;overflow-wrap: break-word !important;">??</span></p><p style="margin-bottom: 15px;max-width: 100%;min-height: 1em;font-size: 16px;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 17px;box-sizing: border-box !important;overflow-wrap: break-word !important;">??????目前流行的 Hash 算法包括 MD5、SHA-1 和 SHA-2拣凹。</span></p><p>???????MD是Message Digest的縮寫茵瘾。</p><p><br /></p><ul data-type="unordered-list" class=" list-paddingleft-2" style=""><li><p style="margin-bottom: 15px;max-width: 100%;min-height: 1em;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 17px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-weight: 700;color: inherit;">MD4</span>(RFC 1320)是 MIT 的 Ronald L. Rivest 在 1990 年設計的,MD 是 Message Digest 的縮寫咐鹤。其輸出為 128 位。MD4 已證明不夠安全圣絮。</span></p></li><li><p style="margin-bottom: 15px;max-width: 100%;min-height: 1em;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 17px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-weight: 700;color: inherit;">MD5</span>(RFC 1321)是 Rivest 于1991年對 MD4 的改進版本祈惶。它對輸入仍以 512 位分組,其輸出是 128 位。MD5 比 MD4 復雜捧请,并且計算速度要慢一點凡涩,更安全一些。MD5 已被證明不具備"強抗碰撞性"(強抗碰撞性參考上面的內容)疹蛉。</span></p></li><li><p style="margin-bottom: 15px;max-width: 100%;min-height: 1em;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 17px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-weight: 700;color: inherit;">SHA</span>?(Secure Hash Algorithm)是一個 Hash 函數族活箕,由 NIST(National Institute of Standards and Technology)于 1993 年發(fā)布第一個算法。目前知名的 SHA-1 在 1995 年面世可款,它的輸出為長度 160 位的 hash 值育韩,因此抗窮舉性更好。SHA-1 設計時基于和 MD4 相同原理闺鲸,并且模仿了該算法筋讨。SHA-1 已被證明不具"強抗碰撞性"。</span></p></li></ul><p><br /></p><section class="xmt-style-block" data-style-type="1" data-tools="新媒體排版" data-id="12991"><section class="KolEditor" style="border-width: 0px;border-style: none;border-color: initial;padding: 0px;"><section style="text-align: center;margin-top:20px;"><section style="display: inline-block;width:20%;margin-right: -16px;"><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span></section><section class="title active" style="display: inline-block;padding: 3px 15px;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);color: rgb(28, 95, 195);font-size: 16px;font-weight: bold;vertical-align: middle;border-radius: 20px;"><p style="min-width: 1em;color:rgb(28,95,195);font-size: 16px;font-weight:bold;">4. hash算法的缺點</p></section><section style="display: inline-block;width:20%;margin-left: -16px;"><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span></section></section></section></section><p><br /></p><p>????????一般而言摸恍,Hash需要較強的算力資源悉罕,所以算力很可能成為hash算法的瓶頸。一般選擇進行hash算法的CPU需要較高的主頻立镶。</p><p><br /></p><section class="xmt-style-block" data-style-type="1" data-tools="新媒體排版" data-id="12991"><section class="KolEditor" style="border-width: 0px;border-style: none;border-color: initial;padding: 0px;"><section style="text-align: center;margin-top:20px;"><section style="display: inline-block;width:20%;margin-right: -16px;"><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span></section><section class="title active" style="display: inline-block;padding: 3px 15px;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);color: rgb(28, 95, 195);font-size: 16px;font-weight: bold;vertical-align: middle;border-radius: 20px;"><p style="min-width: 1em;color:rgb(28,95,195);font-size: 16px;font-weight:bold;">5. Hash算法與數字摘要之間的關系</p></section><section style="display: inline-block;width:20%;margin-left: -16px;"><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span></section></section></section></section><p><br /></p><p>????????數字摘要的意思是對內容進行Hash運算壁袄,把運算結果作為唯一的值來代表之前的值。</p><p><br /></p><p>????????根據前面所學習的內容媚媒,我們可以根據前面所學的hash函數的特點之一(抗碰撞性)來解決確保內容沒有被篡改的問題嗜逻。<br /></p><p><br /></p><p>????????數字摘要是Hash算法的一個很重要的使用場景。當我們在網絡上下載東西的時候欣范,很可能被不法分子篡改变泄,這個時候我們就可以對下載的資源進行數字摘要,這樣當我們下載之后恼琼,通過把下載的文件進行Hash計算妨蛹,把結果與數字摘要進行對比,就可以知道文件是否被篡改晴竞。<br /></p><p><br /></p><section class="xmt-style-block" data-style-type="1" data-tools="新媒體排版" data-id="12991"><section class="KolEditor" style="border-width: 0px;border-style: none;border-color: initial;padding: 0px;"><section style="text-align: center;margin-top:20px;"><section style="display: inline-block;width:20%;margin-right: -16px;"><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span></section><section class="title active" style="display: inline-block;padding: 3px 15px;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);color: rgb(28, 95, 195);font-size: 16px;font-weight: bold;vertical-align: middle;border-radius: 20px;"><p style="min-width: 1em;color:rgb(28,95,195);font-size: 16px;font-weight:bold;">6. 總結</p></section><section style="display: inline-block;width:20%;margin-left: -16px;"><span style="display: inline-block;width: 8px;height: 8px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(28, 95, 195);vertical-align: middle;"></span><span style="display:inline-block;width: 80%;border-bottom:1px solid rgb(28,95,195);vertical-align: middle;"></span></section></section></section></section><p><br /></p><p>????????今天我們學習了Hash算法的概念蛙卤,特點,常用的Hash算法噩死,Hash算法的特點以及Hash算法的應用(數字摘要)等內容颤难。對其有了一個基本的了解。</p>

?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末已维,一起剝皮案震驚了整個濱河市行嗤,隨后出現的幾起案子,更是在濱河造成了極大的恐慌垛耳,老刑警劉巖栅屏,帶你破解...
    沈念sama閱讀 219,366評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件飘千,死亡現場離奇詭異,居然都是意外死亡栈雳,警方通過查閱死者的電腦和手機护奈,發(fā)現死者居然都...
    沈念sama閱讀 93,521評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來哥纫,“玉大人霉旗,你說我怎么就攤上這事≈В” “怎么了厌秒?”我有些...
    開封第一講書人閱讀 165,689評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長松靡。 經常有香客問我简僧,道長,這世上最難降的妖魔是什么雕欺? 我笑而不...
    開封第一講書人閱讀 58,925評論 1 295
  • 正文 為了忘掉前任岛马,我火速辦了婚禮,結果婚禮上屠列,老公的妹妹穿的比我還像新娘啦逆。我一直安慰自己,他們只是感情好笛洛,可當我...
    茶點故事閱讀 67,942評論 6 392
  • 文/花漫 我一把揭開白布夏志。 她就那樣靜靜地躺著,像睡著了一般苛让。 火紅的嫁衣襯著肌膚如雪沟蔑。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,727評論 1 305
  • 那天狱杰,我揣著相機與錄音瘦材,去河邊找鬼。 笑死仿畸,一個胖子當著我的面吹牛食棕,可吹牛的內容都是我干的。 我是一名探鬼主播错沽,決...
    沈念sama閱讀 40,447評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼簿晓,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了千埃?” 一聲冷哼從身側響起憔儿,我...
    開封第一講書人閱讀 39,349評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎放可,沒想到半個月后皿曲,有當地人在樹林里發(fā)現了一具尸體唱逢,經...
    沈念sama閱讀 45,820評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,990評論 3 337
  • 正文 我和宋清朗相戀三年屋休,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片备韧。...
    茶點故事閱讀 40,127評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡劫樟,死狀恐怖,靈堂內的尸體忽然破棺而出织堂,到底是詐尸還是另有隱情叠艳,我是刑警寧澤,帶...
    沈念sama閱讀 35,812評論 5 346
  • 正文 年R本政府宣布易阳,位于F島的核電站附较,受9級特大地震影響,放射性物質發(fā)生泄漏潦俺。R本人自食惡果不足惜拒课,卻給世界環(huán)境...
    茶點故事閱讀 41,471評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望事示。 院中可真熱鬧早像,春花似錦、人聲如沸肖爵。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽劝堪。三九已至冀自,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間秒啦,已是汗流浹背熬粗。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留帝蒿,地道東北人荐糜。 一個月前我還...
    沈念sama閱讀 48,388評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像葛超,于是被迫代替她去往敵國和親暴氏。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,066評論 2 355

推薦閱讀更多精彩內容