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

  • <tfoot id='A4ajq'></tfoot>

    <legend id='A4ajq'><style id='A4ajq'><dir id='A4ajq'><q id='A4ajq'></q></dir></style></legend>

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

      • <bdo id='A4ajq'></bdo><ul id='A4ajq'></ul>

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

        使用 C# 和 CryptoJS 的不同加密結果

        Different encryption results using C# and CryptoJS(使用 C# 和 CryptoJS 的不同加密結果)
        <legend id='0iZOt'><style id='0iZOt'><dir id='0iZOt'><q id='0iZOt'></q></dir></style></legend>

                <tbody id='0iZOt'></tbody>
                <tfoot id='0iZOt'></tfoot>

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

                <small id='0iZOt'></small><noframes id='0iZOt'>

                  <bdo id='0iZOt'></bdo><ul id='0iZOt'></ul>

                • 本文介紹了使用 C# 和 CryptoJS 的不同加密結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我在用 C# 編寫的服務器應用程序中使用 AES 加密了一些數據.例如,我使用預定義的密鑰(32 字節)和 IV(16 字節)...

                  I encrypt some data using AES in a server application, which is written in C#. I use a predefined key (32 bytes) and IV (16 bytes), for instance...

                  Key: 81fe1681..6a451c1c
                  IV:  e83c..ae76
                  

                  這是我用來加密數據的 C# 代碼:

                  This is my C# code I use to encrypt the data:

                  async Task<byte[]> Encrypt(string privateKey, string pin, byte[] data)
                  {
                      using (var sha = SHA256.Create())
                      {
                          byte[] keyHash = sha.ComputeHash(Encoding.UTF8.GetBytes($"{privateKey}"));
                          byte[] pinHash = sha.ComputeHash(Encoding.UTF8.GetBytes($"{pin}"));
                          using (Aes aes = Aes.Create())
                          {
                              byte[] key = keyHash.Slice(0, aes.Key.Length);
                              byte[] iv = pinHash.Slice(0, aes.IV.Length);
                              using (ICryptoTransform transform = aes.CreateEncryptor(key, iv))
                              using (var stream = new MemoryStream())
                              using (var cryptStream = new CryptoStream(stream, transform, CryptoStreamMode.Write))
                              {
                                  await cryptStream.WriteAsync(data, 0, data.Length);
                                  await cryptStream.FlushAsync();
                  
                                  return stream.ToArray();
                              }
                          }
                      }
                  }
                  

                  加密的結果數據看起來像...

                  The encrypted result data looks like...

                  534c..28f5
                  

                  現在,我想使用 CryptoJS 解密客戶端應用程序中的數據.我使用完全相同的密鑰和IV信息,但解密似乎失敗了……至少解密的結果總是空的.

                  Now, I want to decrypt the data in a client application using CryptoJS. I use the exact same key and IV information, but decryption seems to fail... at least the decrypted result is always empty.

                  所以,我在客戶端加密了數據(當然密鑰和 IV 相同),結果密文不同;更準確地說,它是相同的,但最后有更多數據......

                  So, I encrypted the data on the client (of course same key and IV) and in result the ciphered text is different; more precisely it is identical but has more data at the end...

                  534c..28f5bbd5..ac0e
                  

                  如果我對服務器上的數據進行加密,我最后得不到的額外數據是什么?

                  What is this additional data at the end that I don′t get if I encrypt the data on the server?

                  如果我解密已在客戶端加密的密文,則解密有效.順便提一下,模式和填充在服務器和客戶端都是默認的,即CBCPkcs7;密鑰大小應為 256.這是我用來解密服務器加密的數據的代碼:

                  If I decrypt the ciphered text that has been encrypted on the client, the decryption works. Just to mention it, mode and padding are default on both server and client, which is CBC and Pkcs7; keysize should be 256. This is the code I use to decrypt the data that has been ciphered by the server:

                  let keyHash: WordArray = CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(privateKey));
                  let key: WordArray = CryptoJS.lib.WordArray.create(keyHash.words.slice(0, 8), 32);
                  
                  let pinHash: WordArray = CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(pin));
                  let iv: WordArray = CryptoJS.lib.WordArray.create(pinHash.words.slice(0, 4), 16);
                  
                  let cfg: CryptoJS.lib.IBlockCipherCfg = { iv: iv };
                  let paramsData: CryptoJS.lib.CipherParamsData = { 
                      ciphertext: cipherBuffer
                  };
                  
                  let decrypted: WordArray = CryptoJS.AES.decrypt(paramsData, key, cfg);
                  

                  推薦答案

                  對于寫入,塊的刷新出現問題.FlushFinalBlock() 不同于 Flush()(或 FlushAsync()).您必須同時執行它們,或者簡單地處理 CryptoStream.這將解決代碼沒有寫入最后一個數據塊的事實.

                  For the write there was a problem with the flushing of the blocks. The FlushFinalBlock() is distinct from the Flush() (or from the FlushAsync()). You have to do them both, or simply dispose the CryptoStream. This will solve the fact that the code wasn't writing the last block of data.

                  async static Task<byte[]> Encrypt(string privateKey, string pin, byte[] data)
                  {
                      using (var sha = SHA256.Create())
                      {
                          byte[] keyHash = sha.ComputeHash(Encoding.UTF8.GetBytes($"{privateKey}"));
                          byte[] pinHash = sha.ComputeHash(Encoding.UTF8.GetBytes($"{pin}"));
                          using (Aes aes = Aes.Create())
                          {
                              byte[] key = keyHash.Slice(0, aes.Key.Length);
                              byte[] iv = pinHash.Slice(0, aes.IV.Length);
                  
                              Trace.WriteLine($"Key length: { key.Length }, iv length: { iv.Length }, block mode: { aes.Mode }, padding: { aes.Padding }");
                  
                              using (var stream = new MemoryStream())
                              using (ICryptoTransform transform = aes.CreateEncryptor(key, iv))
                              {
                                  using (var cryptStream = new CryptoStream(stream, transform, CryptoStreamMode.Write))
                                  {
                                      await cryptStream.WriteAsync(data, 0, data.Length);
                                  }
                  
                                  return stream.ToArray();
                              }
                          }
                      }
                  }
                  

                  打字稿代碼似乎可以解密.

                  The typescript code seems to be able to decrypt it.

                  工作小提琴:https://jsfiddle.net/uj58twrr/3/

                  這篇關于使用 C# 和 CryptoJS 的不同加密結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                  <i id='r7PUb'><tr id='r7PUb'><dt id='r7PUb'><q id='r7PUb'><span id='r7PUb'><b id='r7PUb'><form id='r7PUb'><ins id='r7PUb'></ins><ul id='r7PUb'></ul><sub id='r7PUb'></sub></form><legend id='r7PUb'></legend><bdo id='r7PUb'><pre id='r7PUb'><center id='r7PUb'></center></pre></bdo></b><th id='r7PUb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='r7PUb'><tfoot id='r7PUb'></tfoot><dl id='r7PUb'><fieldset id='r7PUb'></fieldset></dl></div>

                  <tfoot id='r7PUb'></tfoot>
                    • <small id='r7PUb'></small><noframes id='r7PUb'>

                      • <bdo id='r7PUb'></bdo><ul id='r7PUb'></ul>

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

                              <tbody id='r7PUb'></tbody>
                          1. 主站蜘蛛池模板: 日本在线免费视频 | 久久国产精品免费视频 | 免费成人午夜 | 天天天操操操 | 亚洲视频一区二区三区 | 国产一区二区三区四区在线观看 | 久久久不卡网国产精品一区 | 国产999精品久久久久久绿帽 | 日韩爱爱网 | 久久高清 | 国产精品国产三级国产aⅴ中文 | 国产精品乱码一区二三区小蝌蚪 | 国产成人精品午夜视频免费 | 欧美黄色一区 | 日韩欧美网 | 在线看一区二区三区 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 国产成人99久久亚洲综合精品 | 久久精品一 | 91视视频在线观看入口直接观看 | 黄色片在线免费看 | 亚洲成人精品一区 | 天天看天天摸天天操 | 午夜一区二区三区在线观看 | 超碰在线亚洲 | 高清黄色网址 | 久草在线 | 欧美久久免费观看 | 99免费视频 | 国产中文在线观看 | 成人午夜在线 | 97精品超碰一区二区三区 | 中文成人在线 | 91美女视频| 一级二级三级在线观看 | 九一在线观看 | 91视频88av| 日韩视频一区 | 亚洲热在线视频 | www.97国产 | 91久久|