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

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

          <bdo id='EYBOJ'></bdo><ul id='EYBOJ'></ul>

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

        <tfoot id='EYBOJ'></tfoot>

        充氣城堡 C# 中的 PBKDF2

        PBKDF2 in Bouncy Castle C#(充氣城堡 C# 中的 PBKDF2)
        <legend id='FFLBo'><style id='FFLBo'><dir id='FFLBo'><q id='FFLBo'></q></dir></style></legend>
        <i id='FFLBo'><tr id='FFLBo'><dt id='FFLBo'><q id='FFLBo'><span id='FFLBo'><b id='FFLBo'><form id='FFLBo'><ins id='FFLBo'></ins><ul id='FFLBo'></ul><sub id='FFLBo'></sub></form><legend id='FFLBo'></legend><bdo id='FFLBo'><pre id='FFLBo'><center id='FFLBo'></center></pre></bdo></b><th id='FFLBo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FFLBo'><tfoot id='FFLBo'></tfoot><dl id='FFLBo'><fieldset id='FFLBo'></fieldset></dl></div>
          <bdo id='FFLBo'></bdo><ul id='FFLBo'></ul>

              • <tfoot id='FFLBo'></tfoot>
                  <tbody id='FFLBo'></tbody>

                • <small id='FFLBo'></small><noframes id='FFLBo'>

                  本文介紹了充氣城堡 C# 中的 PBKDF2的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我一直在搞亂 C# Bouncy Castle API 以尋找如何進(jìn)行 PBKDF2 密鑰派生.

                  I've being messing around the C# Bouncy Castle API to find how to do a PBKDF2 key derivation.

                  我現(xiàn)在真的一無(wú)所知.

                  我嘗試閱讀 Pkcs5S2ParametersGenerator.cs 和 PBKDF2Params.cs 文件,但我真的不知道該怎么做.

                  I tried reading through the Pkcs5S2ParametersGenerator.cs and PBKDF2Params.cs files but i really cant figure out how to do it.

                  根據(jù)我目前所做的研究,PBKDF2 需要一個(gè)字符串(或 char[]),即密碼、鹽和迭代次數(shù).

                  According to the research I have done so far, PBKDF2 requires a string (or char[]) which is the password, a salt and an iteration count.

                  到目前為止,我最有希望和最明顯的是 PBKDF2Params 和 Pkcs5S2ParametersGenerator.

                  So far the most promising and most obvious i've come so far is the PBKDF2Params and Pkcs5S2ParametersGenerator.

                  這些似乎都不接受字符串或 char[].

                  None of these seems to be accepting a string or a char[].

                  有沒(méi)有人在 C# 中做過(guò)這個(gè)或?qū)Υ擞腥魏尉€(xiàn)索?或者也許有人用 Java 實(shí)現(xiàn)了 BouncyCastle 并且可以提供幫助?

                  Has anyone done this in C# or have any clue about this? Or perhaps someone who has implemented BouncyCastle in Java and can help?

                  提前感謝很多:)

                  更新:我在 Bouncy Castle 中找到了如何做到這一點(diǎn).看看下面的答案:)

                  UPDATE: I have found how to do this in Bouncy Castle. Look below for answer :)

                  推薦答案

                  經(jīng)過(guò)幾個(gè)小時(shí)的代碼檢查,我發(fā)現(xiàn)最簡(jiǎn)單的方法是在 Pkcs5S2ParametersGenerator.cs 和創(chuàng)建我自己的課程,當(dāng)然使用其他 BouncyCastle API.這與 Dot Net Compact Framework (Windows Mobile) 完美配合.這相當(dāng)于點(diǎn)網(wǎng)緊湊框架 2.0/3.5 中不存在的 Rfc2898DeriveBytes 類(lèi).好吧,也許不是確切的等價(jià)物,但可以完成工作:)

                  After hours and hours of going through the code, I found that the easiest way to do this is to take a few parts of the code in Pkcs5S2ParametersGenerator.cs and create my own class which of course use other BouncyCastle API's. This works perfectly with the Dot Net Compact Framework (Windows Mobile). This is the equivalent of Rfc2898DeriveBytes class which is not present in the Dot Net Compact Framework 2.0/3.5. Well, maybe not the EXACT equivalent but does the job :)

                  這是 PKCS5/PKCS#5

                  This is PKCS5/PKCS#5

                  使用的 PRF(偽隨機(jī)函數(shù))將是 HMAC-SHA1

                  The PRF (Pseudo Random Function) which is used will be HMAC-SHA1

                  第一件事,第一.從 http://www.bouncycastle.org/csharp/ 下載 Bouncy Castle 編譯程序集,添加BouncyCastle.Crypto.dll 作為對(duì)您項(xiàng)目的引用.

                  First things, first. Download the Bouncy Castle compiled assembly from http://www.bouncycastle.org/csharp/, add the BouncyCastle.Crypto.dll as a reference to your project.

                  然后使用下面的代碼創(chuàng)建新的類(lèi)文件.

                  After that create new class file with the code below.

                  using System;
                  using Org.BouncyCastle.Crypto;
                  using Org.BouncyCastle.Crypto.Parameters;
                  using Org.BouncyCastle.Crypto.Digests;
                  using Org.BouncyCastle.Crypto.Macs;
                  using Org.BouncyCastle.Math;
                  using Org.BouncyCastle.Security;
                  
                  namespace PBKDF2_PKCS5
                  {
                      class PBKDF2
                      {
                  
                          private readonly IMac hMac = new HMac(new Sha1Digest());
                  
                          private void F(
                              byte[] P,
                              byte[] S,
                              int c,
                              byte[] iBuf,
                              byte[] outBytes,
                              int outOff)
                          {
                              byte[] state = new byte[hMac.GetMacSize()];
                              ICipherParameters param = new KeyParameter(P);
                  
                              hMac.Init(param);
                  
                              if (S != null)
                              {
                                  hMac.BlockUpdate(S, 0, S.Length);
                              }
                  
                              hMac.BlockUpdate(iBuf, 0, iBuf.Length);
                  
                              hMac.DoFinal(state, 0);
                  
                              Array.Copy(state, 0, outBytes, outOff, state.Length);
                  
                              for (int count = 1; count != c; count++)
                              {
                                  hMac.Init(param);
                                  hMac.BlockUpdate(state, 0, state.Length);
                                  hMac.DoFinal(state, 0);
                  
                                  for (int j = 0; j != state.Length; j++)
                                  {
                                      outBytes[outOff + j] ^= state[j];
                                  }
                              }
                          }
                  
                          private void IntToOctet(
                              byte[] Buffer,
                              int i)
                          {
                              Buffer[0] = (byte)((uint)i >> 24);
                              Buffer[1] = (byte)((uint)i >> 16);
                              Buffer[2] = (byte)((uint)i >> 8);
                              Buffer[3] = (byte)i;
                          }
                  
                          // Use this function to retrieve a derived key.
                          // dkLen is in octets, how much bytes you want when the function to return.
                          // mPassword is the password converted to bytes.
                          // mSalt is the salt converted to bytes
                          // mIterationCount is the how much iterations you want to perform. 
                          
                  
                          public byte[] GenerateDerivedKey(
                              int dkLen,
                              byte[] mPassword,
                              byte[] mSalt,
                              int mIterationCount
                              )
                          {
                              int hLen = hMac.GetMacSize();
                              int l = (dkLen + hLen - 1) / hLen;
                              byte[] iBuf = new byte[4];
                              byte[] outBytes = new byte[l * hLen];
                  
                              for (int i = 1; i <= l; i++)
                              {
                                  IntToOctet(iBuf, i);
                  
                                  F(mPassword, mSalt, mIterationCount, iBuf, outBytes, (i - 1) * hLen);
                              }
                  
                          //By this time outBytes will contain the derived key + more bytes.
                         // According to the PKCS #5 v2.0: Password-Based Cryptography Standard (www.truecrypt.org/docs/pkcs5v2-0.pdf) 
                         // we have to "extract the first dkLen octets to produce a derived key".
                  
                         //I am creating a byte array with the size of dkLen and then using
                         //Buffer.BlockCopy to copy ONLY the dkLen amount of bytes to it
                         // And finally returning it :D
                  
                          byte[] output = new byte[dkLen];
                  
                          Buffer.BlockCopy(outBytes, 0, output, 0, dkLen);
                  
                          return output;
                          }
                  
                  
                      }
                  }
                  

                  那么如何使用這個(gè)功能呢?簡(jiǎn)單的!:)這是一個(gè)非常簡(jiǎn)單的示例,其中密碼和鹽由用戶(hù)提供.

                  So how to use this function? Simple! :) This is a very simple example where the password and the salt is provided by the user.

                  private void cmdDeriveKey_Click(object sender, EventArgs e)
                          {
                              byte[] salt = ASCIIEncoding.UTF8.GetBytes(txtSalt.Text);
                  
                              PBKDF2 passwordDerive = new PBKDF2();
                              
                  
                        // I want the key to be used for AES-128, thus I want the derived key to be
                        // 128 bits. Thus I will be using 128/8 = 16 for dkLen (Derived Key Length) . 
                        //Similarly if you wanted a 256 bit key, dkLen would be 256/8 = 32. 
                  
                              byte[] result = passwordDerive.GenerateDerivedKey(16, ASCIIEncoding.UTF8.GetBytes(txtPassword.Text), salt, 1000);
                  
                             //result would now contain the derived key. Use it for whatever cryptographic purpose now :)
                             //The following code is ONLY to show the derived key in a Textbox.
                  
                              string x = "";
                  
                              for (int i = 0; i < result.Length; i++)
                              {
                                  x += result[i].ToString("X");
                              }
                  
                              txtResult.Text = x;
                  
                          }
                  

                  如何檢查這是否正確?有一個(gè) PBKDF2 的在線(xiàn) javascript 實(shí)現(xiàn)http://anandam.name/pbkdf2/

                  How to check whether this is correct? There is an online javascript implementation of PBKDF2 http://anandam.name/pbkdf2/

                  我得到了一致的結(jié)果 :)如果有人得到不正確的結(jié)果,請(qǐng)報(bào)告:)

                  I got consistent results :) Please report if anyone is getting an incorrect result :)

                  希望這可以幫助某人:)

                  Hope this helps someone :)

                  更新:確認(rèn)使用此處提供的測(cè)試向量

                  UPDATE: Confirmed working with test vectors provided here

                  https://datatracker.ietf.org/doc/html/draft-josefsson-pbkdf2-test-vectors-00

                  更新:或者,對(duì)于鹽,我們可以使用 RNGCryptoServiceProvider.確保引用 System.Security.Cryptography 命名空間.

                  UPDATE: Alternatively, for the salt we can use a RNGCryptoServiceProvider. Make sure to reference the System.Security.Cryptography namespace.

                  RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();        
                              
                  byte[] salt = new byte[16];
                  
                  rng.GetBytes(salt);
                  

                  這篇關(guān)于充氣城堡 C# 中的 PBKDF2的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  What are good algorithms for vehicle license plate detection?(車(chē)牌檢測(cè)有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運(yùn)行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時(shí)刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時(shí)突出顯示行)
                  Calling A Button OnClick from a function(從函數(shù)調(diào)用按鈕 OnClick)
                  <tfoot id='JLhSC'></tfoot>

                    • <legend id='JLhSC'><style id='JLhSC'><dir id='JLhSC'><q id='JLhSC'></q></dir></style></legend>

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

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

                        <bdo id='JLhSC'></bdo><ul id='JLhSC'></ul>

                          • 主站蜘蛛池模板: 亚洲成人精品一区 | hsck成人网 | 欧美国产中文字幕 | 欧美精品久久久久 | 国产精品福利在线 | 影音先锋亚洲资源 | 夜夜爽99久久国产综合精品女不卡 | 日本精品在线一区 | 亚洲视频免费在线播放 | 国产婷婷精品 | 男人天堂999| 国产乱码精品一区二区三区五月婷 | 欧美视频 | 国产视频在线观看一区二区三区 | 99亚洲精品视频 | 成人在线播放 | 欧美激情精品久久久久久 | 国产91丝袜在线18 | 伊人在线 | 射欧美 | 日韩图区 | 天天看天天爽 | 超碰97在线免费 | 中文二区 | 97在线观视频免费观看 | 日韩三级在线 | 久久久久国产一区二区三区四区 | 精品久久久久久久久久久 | 成人毛片在线观看 | 黄色免费三级 | 久久久国产精品 | 日韩一二三区视频 | 久草青青草 | 九九热国产精品视频 | 中文字幕日韩欧美 | 本道综合精品 | 欧美13videosex性极品 | 国产激情视频网站 | 日韩福利视频 | 涩涩视频在线观看免费 | 亚洲免费高清 |