久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <i id='oMNXu'><tr id='oMNXu'><dt id='oMNXu'><q id='oMNXu'><span id='oMNXu'><b id='oMNXu'><form id='oMNXu'><ins id='oMNXu'></ins><ul id='oMNXu'></ul><sub id='oMNXu'></sub></form><legend id='oMNXu'></legend><bdo id='oMNXu'><pre id='oMNXu'><center id='oMNXu'></center></pre></bdo></b><th id='oMNXu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oMNXu'><tfoot id='oMNXu'></tfoot><dl id='oMNXu'><fieldset id='oMNXu'></fieldset></dl></div>

    <small id='oMNXu'></small><noframes id='oMNXu'>

    <tfoot id='oMNXu'></tfoot>

      <legend id='oMNXu'><style id='oMNXu'><dir id='oMNXu'><q id='oMNXu'></q></dir></style></legend>
      • <bdo id='oMNXu'></bdo><ul id='oMNXu'></ul>
    1. openssl_digest vs hash vs hash_hmac?SALT 和 SALT 的區別HM

      openssl_digest vs hash vs hash_hmac? Difference between SALT amp; HMAC?(openssl_digest vs hash vs hash_hmac?SALT 和 SALT 的區別HMAC?)

            <small id='agGkB'></small><noframes id='agGkB'>

          • <legend id='agGkB'><style id='agGkB'><dir id='agGkB'><q id='agGkB'></q></dir></style></legend>
              <tbody id='agGkB'></tbody>

            <tfoot id='agGkB'></tfoot>
            <i id='agGkB'><tr id='agGkB'><dt id='agGkB'><q id='agGkB'><span id='agGkB'><b id='agGkB'><form id='agGkB'><ins id='agGkB'></ins><ul id='agGkB'></ul><sub id='agGkB'></sub></form><legend id='agGkB'></legend><bdo id='agGkB'><pre id='agGkB'><center id='agGkB'></center></pre></bdo></b><th id='agGkB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='agGkB'><tfoot id='agGkB'></tfoot><dl id='agGkB'><fieldset id='agGkB'></fieldset></dl></div>
              <bdo id='agGkB'></bdo><ul id='agGkB'></ul>
                本文介紹了openssl_digest vs hash vs hash_hmac?SALT 和 SALT 的區別HMAC?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我想使用 SHA512 來存儲密碼.為此,我應該使用 openssl_digesthashhash_hmac 中的哪一個,為什么?

                I want to use SHA512 to store passwords. To do that, which of openssl_digest, hash and hash_hmac should I use and why?

                SALT 和有什么區別?HMAC?

                我剛剛讀到 HMAC 是建立在哈希函數之上的.

                I just read that HMAC is built on top of hash function.

                那么SHA512+SALT+HMAC真的有必要還是SHA512+SALTSHA512+HMAC?

                So is SHA512+SALT+HMAC really necessary or SHA512+SALT or SHA512+HMAC?

                推薦答案

                所以,首先,讓我們弄清楚一件事.openssl_digest() === hash().它只是另一個名稱不同的函數,它執行完全相同的操作.它計算輸入的加密哈希.

                So, first off, let's clear one thing up. openssl_digest() === hash(). It's just another function by a different name that does the exact same thing. It computes a cryptographic hash of the input.

                那么,現在我們有一個問題:存儲密碼時,哪個更好:hash 還是 hash_hmac?

                So, now we have the question: When storing passwords, which is better: hash or hash_hmac?

                都沒有

                事實證明,彩虹桌已死.僅使用 hash($password . $salt) 甚至 hash_hmac($password, $salt) 都不足以存儲密碼.時期.如果您正在這樣做,請立即停止.

                As it turns out, The Rainbow Table Is Dead. Just using hash($password . $salt) or even hash_hmac($password, $salt) is not good enough for password storage. Period. If you're doing so, stop right now.

                原因很簡單:計算機(或 GPU)上的計算時間非常便宜.它太便宜了,以致于對密碼列表進行暴力破解已經足夠便宜,您需要擔心它.請記住,哈希函數旨在快速.不貴...

                The reason is simple: computation time on a computer (or GPU) is incredibly cheap. It's so cheap, that to brute force a list of passwords is cheap enough that you need to worry about it. Remember, hash functions are designed to be fast. Not expensive...

                但是,事實證明,有一種方法可以使那些快速散列函數更加昂貴.事實上,它非常簡單:迭代.

                But, as it also turns out, there is a way to make those fast hash functions more expensive. In fact, it's pretty simple: iterate.

                現在,我知道你在想什么.您將只循環遍歷哈希:

                Now, I know what you're thinking. You're going to just loop over the hash:

                function hash_password($password, $salt) {
                    $hash = hash("sha512", $password . $salt);
                    for ($i = 0; $i < 1000; $i++) {
                        $hash = hash("sha512", $hash);
                    }
                }
                

                當然夠好了,對吧?不.正如散列和加密之間的根本區別中所述,這不是一個好主意.那么為什么不直接反饋密碼并再次加鹽呢?

                Surely that's good enough, right? Nope. As explained in Fundamental Difference Between Hashing and Encryption, that's not a good idea. So why not just feed back the password and salt in again?

                function hash_password($password, $salt) {
                    $hash = hash("md5", $salt . $password);
                    for ($i = 0; $i < 1000; $i++) {
                        $hash = hash("md5", $hash . $password);
                    }
                }
                

                事實上,這正是 PHPASS 使用的(略有調整,但這是基本算法)...

                In fact, this is exactly what PHPASS uses (slightly tweaked, but this is the base algorithm)...

                所以現在對 hash_password 的 1 次調用會執行 1000 個哈希周期.

                So now 1 call to hash_password executes 1000 hash cycles.

                但是我們可以改進嗎?

                好吧,事實證明,我們可以.下一個合乎邏輯的事情是看看我們是否可以在相同的時間內獲得更多的哈希周期.這就是 hash_hmac() 的用武之地.事實證明,HMAC 每次被調用時使用 2 個哈希周期.而且因為它都是 C 語言,所以它只需要 hash() 完成一輪所需的時間的 1.5 倍左右.

                Well, as it turns out, we can. The next logical thing to do would be to see if we can get more hash cycles for the same amount of time. And this is where hash_hmac() comes in. As it turns out, HMAC uses 2 hash cycles each time it's called. And because it's all C, it only takes about 1.5 times the amount of time that hash() takes to do a single round.

                這意味著如果我們將 hash 替換為 hash_hmac,我們可以立即看到在指定時間內完成的工作量增加了 33%.所以現在我們在這里:

                So that means if we replace hash with hash_hmac, we can instantly see a 33% increase in the amount of work being done in a specified time. So now we're here:

                function hash_password($password, $salt) {
                    $hash = hash_hmac("md5", $salt, $password);
                    for ($i = 0; $i < 1000; $i++) {
                        $hash = hash_hmac("md5", $hash, $password);
                    }
                }
                

                這實際上是PBKDF2的基本內循環.

                And this is actually the basic inner-loop of PBKDF2.

                但我們能變得更好嗎?

                是的,我們可以變得更好.如果我們仔細觀察,我們會發現——除了密碼和鹽之外——上述所有算法都使用了非常少的內存.在 sha512 的情況下,他們將使用大約 128 到 256 個字節(緩沖區和狀態)來散列密碼.由于內存使用量非常小,因此在 GPU 中同時并排運行很多內存是微不足道的.如果我們只能增加內存使用...

                Yes, again, we can get better. If we look closely, we can see that -in addition to password and salt- all of the above algorithms use a very small amount of memory. In the case of sha512, they'll use on the order of 128 to 256 bytes (buffers and state) to hash the password. Since the memory use is so small, it's trivial to run a lot of them at once side-by-side in a GPU. If we could only increase the memory usage...

                好吧,事實證明,我們可以簡單地使用 bcrypt,這是一種自適應散列算法.它的優勢在于它比上述算法使用更多的內存(大約 4 到 5kb).所以它更難并行化.由于計算成本高昂,因此它可以抵抗暴力破解.

                Well, as it turns out, we can simply use bcrypt, which is an adaptive hashing algorithm. It has an advantage that it uses more memory than the above algorithms (on the order of 4 to 5kb). So it's more resistent to parallelizing. And it's resistent to brute forcing since it's computationally expensive.

                幸運的是,它可用于 PHP:

                Luckily, it's available for PHP:

                crypt($password, '$2y$07$usesomesillystringforsalt$')
                

                注意 crypt() 使用了很多算法,但是 $2y$$2a$ 算法是 bcrypt.

                Note that crypt() uses many algorithms, but the $2y$ and $2a$ algorithms are bcrypt.

                但是我們可以改進嗎?

                有點.有一種相對較新的算法,稱為 scrypt.它比 bcrypt 更好,因為它在計算上同樣昂貴,但使用了更多的內存(大約 20mb 到 40mb 來散列單個密碼).因此,它更難并行化...

                Kind-of. There is a relatively new algorithm called scrypt. It's better than bcrypt, because it's just as computationally expensive, but uses a LOT more memory (on the order of 20mb to 40mb to hash a single password). Therefore, it's even more resistent to parallelization...

                不幸的是,scrypt 在 PHP 中 不可用(我正在努力改變它).在那之前,使用 bcrypt...

                Unfortunately, scrypt is not available in PHP yet (I'm working on changing that). Until then, use bcrypt...

                最近從 LinkedIn 吸取教訓后,LastFM、Hotmail,Gawker 等,證明很多的人都做錯了.不要做錯,使用帶有經過審查的算法的庫.使用CRYPT_BLOWFISH (bcrypt),使用PHPASS,使用PasswordLib.但是不要僅僅因為你不想拉依賴關系就發明你自己的......那只是疏忽.

                After the recent lessons from LinkedIn, LastFM, Hotmail, Gawker, etc, the proof is apparent that a lot of people are doing it wrong. Don't do it wrong, use a library with a vetted algorithm. Use CRYPT_BLOWFISH (bcrypt), use PHPASS, use PasswordLib. But don't invent your own just because you don't want to pull a dependency... That's just negligence.

                更多閱讀:

                • 正確加鹽密碼 - 反對 Pepper 的案例
                • GPU 加速 PBKDF2
                • 多次哈希迭代,每次都追加鹽?
                • MD5 解碼,他們是怎么做的

                這篇關于openssl_digest vs hash vs hash_hmac?SALT 和 SALT 的區別HMAC?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                  • <legend id='5pbBh'><style id='5pbBh'><dir id='5pbBh'><q id='5pbBh'></q></dir></style></legend>

                      <i id='5pbBh'><tr id='5pbBh'><dt id='5pbBh'><q id='5pbBh'><span id='5pbBh'><b id='5pbBh'><form id='5pbBh'><ins id='5pbBh'></ins><ul id='5pbBh'></ul><sub id='5pbBh'></sub></form><legend id='5pbBh'></legend><bdo id='5pbBh'><pre id='5pbBh'><center id='5pbBh'></center></pre></bdo></b><th id='5pbBh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5pbBh'><tfoot id='5pbBh'></tfoot><dl id='5pbBh'><fieldset id='5pbBh'></fieldset></dl></div>
                      <tfoot id='5pbBh'></tfoot>
                        <tbody id='5pbBh'></tbody>
                        <bdo id='5pbBh'></bdo><ul id='5pbBh'></ul>

                          <small id='5pbBh'></small><noframes id='5pbBh'>

                          主站蜘蛛池模板: 国产乱码精品1区2区3区 | 国产一级影片 | 一区二区三区福利视频 | 精品久久久久久久久久久院品网 | 免费观看毛片 | 欧美亚洲国产一区二区三区 | 国产精品欧美一区二区三区不卡 | 狠狠狠色丁香婷婷综合久久五月 | 亚洲国产精品日韩av不卡在线 | 亚洲电影专区 | 亚洲不卡在线观看 | 欧美激情在线播放 | 欧美亚洲另类丝袜综合网动图 | 青青操91| 欧美激情久久久 | 91精品欧美久久久久久久 | 午夜电影福利 | 国产精品福利网站 | 成人精品毛片国产亚洲av十九禁 | 久草网址 | 婷婷国产一区 | 天天综合久久 | 一区二区在线 | 日韩视频在线一区 | 一区二区三区在线电影 | 国产精品美女久久久久久久久久久 | 久久久一区二区三区 | av中文字幕在线 | 色呦呦网站 | 欧美乱人伦视频 | 日韩在线视频免费观看 | 久久精品国产免费一区二区三区 | 国产一区二区三区精品久久久 | 亚洲国产精品视频一区 | 97超在线视频 | 亚州影院 | 色婷婷亚洲国产女人的天堂 | 三级在线视频 | 99久久精品免费看国产四区 | 国产成人精品久久二区二区 | 亚洲一区二区三区四区五区中文 |