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

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

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

      2. <tfoot id='TpYQb'></tfoot>

        解密異常 - 要解密的數(shù)據(jù)長(zhǎng)度無(wú)效

        Decryption Exception - length of the data to decrypt is invalid(解密異常 - 要解密的數(shù)據(jù)長(zhǎng)度無(wú)效)
      3. <small id='rqxoT'></small><noframes id='rqxoT'>

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

                1. 本文介紹了解密異常 - 要解密的數(shù)據(jù)長(zhǎng)度無(wú)效的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

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

                  我正在使用 C# 應(yīng)用程序.我們有常用的方法將數(shù)據(jù)存儲(chǔ)在文件中.這些方法加密數(shù)據(jù)并將它們存儲(chǔ)在文件系統(tǒng)上.當(dāng)我們需要數(shù)據(jù)時(shí),ReadData 方法會(huì)解密數(shù)據(jù)并返回給我純文本.

                  I am working in a C# application. We have common methods to store data on a file. These methods encrypt the data and store them on the file system. when we need the data, ReadData method decrypts the data and returns me plain text.

                  如果文本的大小很小,則此代碼在正常情況下可以正常工作.但對(duì)于下面給出的示例文本,解密代碼拋出異常 - 要解密的數(shù)據(jù)長(zhǎng)度無(wú)效.

                  This code works fine in normal cases if size of the text in small. but for a example text given below, the decryption code is throwing exception - length of the data to decrypt is invalid.

                  異常發(fā)生在行

                          // close the CryptoStream
                          x_cryptostream.Close();
                  

                  我嘗試了不同的方法,但沒(méi)有運(yùn)氣.可以請(qǐng)一些幫助.

                  I tried different ways but no luck. Can some pls help.

                  我為什么要加密已經(jīng)加密的數(shù)據(jù)-我只是想使用大型應(yīng)用程序的常用方法將其存儲(chǔ)在文件中.常用方法 storedata(key,data)readdata(key) 做我無(wú)法避免的加密/解密.

                  Why am I encrypting already encrypted data - I am just trying to store in a file using common method of the huge application. The common methods storedata(key,data) nad readdata(key) do the encryption/decryption I can't avoid.

                     public static byte[] Decrypt(byte[] ciphertext, string Key, string IV)
                      {
                          byte[] k = Encoding.Default.GetBytes(Key);
                          byte[] iv = Encoding.Default.GetBytes(IV);
                  
                          // create the encryption algorithm
                          SymmetricAlgorithm x_alg = SymmetricAlgorithm.Create("Rijndael");
                          x_alg.Padding = PaddingMode.PKCS7;
                  
                          // create an ICryptoTransform that can be used to decrypt data
                          ICryptoTransform x_decryptor = x_alg.CreateDecryptor(k, iv);
                  
                          // create the memory stream
                          MemoryStream x_memory_stream = new MemoryStream();
                  
                          // create the CryptoStream that ties together the MemoryStream and the 
                          // ICryptostream
                          CryptoStream x_cryptostream = new CryptoStream(x_memory_stream,
                          x_decryptor, CryptoStreamMode.Write);
                  
                          // write the ciphertext out to the cryptostream
                          x_cryptostream.Write(ciphertext, 0, ciphertext.Length);
                  
                          // close the CryptoStream
                          x_cryptostream.Close();
                  
                          // get the plaintext from the MemoryStream
                          byte[] x_plaintext = x_memory_stream.ToArray();
                  

                  下面是加密方法的代碼.

                  Below is the code of encrypt method.

                          public static byte[] Encrypt(string strplain, string Key, string IV)
                          {
                          byte[] k = Encoding.Default.GetBytes(Key);
                          byte[] iv = Encoding.Default.GetBytes(IV);
                  
                          byte[] plaintext = Encoding.Default.GetBytes(strplain);
                  
                          // create the encryption algorithm
                          SymmetricAlgorithm x_alg = SymmetricAlgorithm.Create("Rijndael");
                          x_alg.Padding = PaddingMode.PKCS7;
                          // create an ICryptoTransform that can be used to encrypt data
                          ICryptoTransform x_encryptor = x_alg.CreateEncryptor(k, iv);
                  
                          // create the memory stream
                          MemoryStream x_memory_stream = new MemoryStream();
                  
                          // create the CryptoStream that ties together the MemoryStream and
                          // the ICryptostream
                          CryptoStream x_cryptostream = new CryptoStream(x_memory_stream,
                          x_encryptor, CryptoStreamMode.Write);
                  
                          // write the plaintext out to the cryptostream
                          x_cryptostream.Write(plaintext, 0, plaintext.Length);
                  
                          // close the CryptoStream
                          x_cryptostream.Close();
                  
                          // get the ciphertext from the MemoryStream
                          byte[] x_ciphertext = x_memory_stream.ToArray();
                  
                          // close memory stream
                          x_memory_stream.Close();
                  
                          // convert from array to string
                          string cipher_Tx = Encoding.Default.GetString(x_ciphertext, 
                              0, x_ciphertext.Length);
                  
                          x_encryptor.Dispose();
                  
                          x_alg.Clear();
                          byte[] cipher = Encoding.Default.GetBytes(cipher_Tx);
                  
                          return cipher;
                      }  
                  

                  推薦答案

                  你的問(wèn)題是string cipher_Tx = Encoding.Default.GetString(x_ciphertext, 0, x_ciphertext.Length);.

                  x_ciphertext 不是文本的有效字節(jié)表示,它有許多無(wú)法呈現(xiàn)的字符,當(dāng)您進(jìn)行 byte[]string 轉(zhuǎn)換時(shí)你正在丟失信息.正確的方法是使用字符串格式,該格式旨在使用 Convert.ToBase64String(byte[])Convert.FromBase64String(string).

                  x_ciphertext is not a valid byte representation of text, it has many unpresentable characters and when you do your byte[] to string conversion you are loosing information. The correct way to do it is use a string format that is designed to represent binary data using something like Convert.ToBase64String(byte[]) and Convert.FromBase64String(string).

                  string cipher_Tx = Convert.ToBase64String(x_ciphertext)
                  
                  x_encryptor.Dispose();
                  
                  x_alg.Clear();
                  byte[] cipher = Convert.FromBase64String(cipher_Tx)
                  

                  話雖如此,您的代碼還有很多其他奇怪"的地方,例如您不使用 using 語(yǔ)句,而您確實(shí)應(yīng)該使用.此外,完全沒(méi)有必要將整個(gè)轉(zhuǎn)換為字符串并返回,只需返回 x_ciphertext.代碼也可能存在其他問(wèn)題(例如 KeyIV 的字符串來(lái)自哪里)和許多其他最佳實(shí)踐(例如您應(yīng)該生成隨機(jī) IV并將其寫(xiě)到輸出中,并且應(yīng)該使用不直接來(lái)自用戶文本的密鑰派生函數(shù)生成密鑰),但是在發(fā)現(xiàn)字符串轉(zhuǎn)換問(wèn)題后我停止了檢查.

                  That being said, there is a lot of other "odd" things about your code, for example you don't use using statements and you really should. Also that whole conversion to string and back is totally unnecessary, just return x_ciphertext. There may be other problems with the code too (like where did the strings for Key and IV come from) and many other best practices (like you should be generating a random IV and writing it out in to the output and the key should be generated using a key derivation function not straight from user text), but I stopped checking after I found the string conversion issue.

                  這篇關(guān)于解密異常 - 要解密的數(shù)據(jù)長(zhǎng)度無(wú)效的文章就介紹到這了,希望我們推薦的答案對(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?(車牌檢測(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)
                  <i id='z5RjX'><tr id='z5RjX'><dt id='z5RjX'><q id='z5RjX'><span id='z5RjX'><b id='z5RjX'><form id='z5RjX'><ins id='z5RjX'></ins><ul id='z5RjX'></ul><sub id='z5RjX'></sub></form><legend id='z5RjX'></legend><bdo id='z5RjX'><pre id='z5RjX'><center id='z5RjX'></center></pre></bdo></b><th id='z5RjX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='z5RjX'><tfoot id='z5RjX'></tfoot><dl id='z5RjX'><fieldset id='z5RjX'></fieldset></dl></div>

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

                        <tfoot id='z5RjX'></tfoot>

                            <tbody id='z5RjX'></tbody>
                            <bdo id='z5RjX'></bdo><ul id='z5RjX'></ul>
                            <legend id='z5RjX'><style id='z5RjX'><dir id='z5RjX'><q id='z5RjX'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 亚洲毛片在线观看 | 国产在线视频在线观看 | 最新av在线网址 | 午夜精品久久久久久久久久久久久 | 欧美一级在线视频 | 91久色 | 亚洲一二三区免费 | 国产精品一区二区久久精品爱微奶 | 久久久噜噜噜www成人网 | 日韩中文字幕免费在线观看 | www国产精品 | 欧美色专区 | 黄色一级网 | www.天天操.com | 不卡在线视频 | 亚洲人在线播放 | 成人精品一区 | 国产成人免费视频网站视频社区 | 欧美在线视频网 | 美女黄色在线观看 | 成人在线免费观看 | 午夜精品三区 | 久久久久久久久久久久久久久久久久久久 | 亚洲免费在线播放 | 国产精品永久久久久久久www | 欧美高清成人 | 成人天堂噜噜噜 | 亚洲美女在线一区 | 欧美一区免费在线观看 | 在线久草| 国产成人免费视频网站高清观看视频 | 精品日韩| 国产色网 | 国产99久久久国产精品下药 | 成人精品区| 91文字幕巨乱亚洲香蕉 | 欧美一区二区大片 | 日本在线视频不卡 | 免费激情 | 成在线人视频免费视频 | caoporn国产 |