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

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

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

        使用 OpenSSL 的 AES-256/CBC 加密和 C# 中的解密

        AES-256/CBC encryption with OpenSSL and decryption in C#(使用 OpenSSL 的 AES-256/CBC 加密和 C# 中的解密)

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

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

                    <tbody id='cC5fR'></tbody>
                • 本文介紹了使用 OpenSSL 的 AES-256/CBC 加密和 C# 中的解密的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我是密碼學(xué)的新手.我的要求是解密/加密使用 openssl 加密/解密的文本.我們使用的算法是 Openssl 中的 aes-256-cbc.所以,我試圖在我的應(yīng)用程序中實現(xiàn)相同的功能.到目前為止,經(jīng)過大量谷歌搜索,我所能做的就是......

                  I am a newbie to cryptography. My requirement is to decrypt/encrypt the text that is encrypted/decrypted using openssl. The algorithm that we are using is aes-256-cbc in the Openssl. So, I am trying to implement the same functionality in my application. so far after a lot of googling all i was able to do is..

                  private static string Encryptor(string TextToEncrypt)
                  {
                      //Turn the plaintext into a byte array.
                      byte[] PlainTextBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(TextToEncrypt);            
                  
                      //Setup the AES providor for our purposes.
                      AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
                  
                      aesProvider.BlockSize = 128;
                      aesProvider.KeySize = 256;  
                      //My key and iv that i have used in openssl
                      aesProvider.Key = System.Text.Encoding.ASCII.GetBytes(strKey);
                      aesProvider.IV = System.Text.Encoding.ASCII.GetBytes(strIV);  
                      aesProvider.Padding = PaddingMode.PKCS7;
                      aesProvider.Mode = CipherMode.CBC;
                  
                      ICryptoTransform cryptoTransform = aesProvider.CreateEncryptor(aesProvider.Key, aesProvider.IV);            
                      byte[] EncryptedBytes = cryptoTransform.TransformFinalBlock(PlainTextBytes, 0, PlainTextBytes.Length);
                      return Convert.ToBase64String(EncryptedBytes);                        
                  }
                  
                  private static string Decryptor(string TextToDecrypt)
                  {
                      byte[] EncryptedBytes = Convert.FromBase64String(TextToDecrypt);
                  
                      //Setup the AES provider for decrypting.            
                      AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
                      //aesProvider.Key = System.Text.Encoding.ASCII.GetBytes(strKey);
                      //aesProvider.IV = System.Text.Encoding.ASCII.GetBytes(strIV);
                      aesProvider.BlockSize = 128;
                      aesProvider.KeySize = 256;  
                      //My key and iv that i have used in openssl
                      aesProvider.Key = System.Text.Encoding.ASCII.GetBytes(strKey);
                      aesProvider.IV = System.Text.Encoding.ASCII.GetBytes(strIV);  
                      aesProvider.Padding = PaddingMode.PKCS7;
                      aesProvider.Mode = CipherMode.CBC;
                  
                  
                      ICryptoTransform cryptoTransform = aesProvider.CreateDecryptor(aesProvider.Key, aesProvider.IV);
                      byte[] DecryptedBytes = cryptoTransform.TransformFinalBlock(EncryptedBytes, 0, EncryptedBytes.Length);
                      return System.Text.Encoding.ASCII.GetString(DecryptedBytes);
                  }
                  

                  我的 openssl 命令是

                  My openssl command is

                  openssl aes-256-cbc -e -nosalt -a -in  inputfile.txt -out  output.txt -k key -iv ivkey
                  

                  我的密鑰長度是 32 位,iv 是 16 位

                  My key length is 32digits and iv is 16digits

                  謝謝...

                  推薦答案

                  首先,閱讀openssl的man enc.使用 -k 時會忽略 -iv.您可能想要大寫 -K.其次,與 openssl 工具一起使用時,key 和 iv 值是十六進(jìn)制的,如果您的 C# 使用與命令行相同的字符串,那么您需要執(zhí)行 適當(dāng)?shù)霓D(zhuǎn)換而不是 Encoding.ASCII.GetBytes(7 位編碼無論如何都不是正確的答案).

                  First, read man enc for openssl. -iv is ignored when -k is used. You probably want capital -K. Second, the key and iv values are hexadecimal when used with the openssl tool, if your C# is using the same string as the command line then you need to do appropriate conversions rather than Encoding.ASCII.GetBytes (a 7 bit encoding is never the right answer anyway).

                  對于純文本,您不妨使用 Encoding.UTF8.GetBytes/GetString,因為它向后兼容 ASCII.

                  For your plain text, you might as well use Encoding.UTF8.GetBytes/GetString since it is backwards compatible with ASCII.

                  如果出于某種原因你真的想使用小寫的-k,一個生成密鑰和iv的密碼,這要困難得多,因為openssl使用它自己的密鑰派生方案.此外,與 -nosalt 標(biāo)志一起使用也很危險.

                  If for some reason you actually want to use lowercase -k, a password to generate both the key and iv, that is much more difficult as openssl uses it's own key derivation scheme. Also, it is dangerous to use with the -nosalt flag.

                  -nosalt:在密鑰派生例程中不使用鹽.這個選項應(yīng)該除非用于測試目的或與古代兼容,否則不得使用OpenSSL 和 SSLeay 的版本.

                  -nosalt: doesn't use a salt in the key derivation routines. This option SHOULD NOT be used except for test purposes or compatibility with ancient versions of OpenSSL and SSLeay.

                  這是危險的原因之一,是因為 IV 不應(yīng)該是可預(yù)測的或不能重復(fù)用于 AES-CBC,如果您不使用鹽,密碼將始終生成具有相同 IV 的相同密鑰這會使您遭受多次攻擊,并可能泄露有關(guān)明文的信息.

                  One of the reasons this is dangerous, is due to the fact that IV's should not be predictable or reused for AES-CBC and if you don't use a salt, the passphrase will always produce the same key with the same IV that opens you up to several attacks and can leak info about the plaintext.

                  您可以從這篇博文中了解如何從密碼短語、與 openssl 相同的密鑰和 IV 派生 在 C# 中解密 OpenSSL AES 文件 雖然它是專門針對 AES-128 的,但注釋會引導(dǎo)您了解如何修改 aes-256,來自 manEVP_BytesToKey:

                  You can find out how to derive from passphrase, the same key and IV as openssl from this blog post Decrypting OpenSSL AES files in C# although it is specifically for AES-128 the comments lead you to how to modify for aes-256, from man EVP_BytesToKey:

                  Hash0 = ''
                  Hash1 = MD5(Hash0 + Password + Salt)
                  Hash2 = MD5(Hash1 + Password + Salt)
                  Hash3 = MD5(Hash2 + Password + Salt)
                  
                  Key = Hash1 + Hash2
                  IV = Hash3
                  

                  這篇關(guān)于使用 OpenSSL 的 AES-256/CBC 加密和 C# 中的解密的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  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# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數(shù)調(diào)用按鈕 OnClick)
                  <tfoot id='brWBV'></tfoot>
                  <i id='brWBV'><tr id='brWBV'><dt id='brWBV'><q id='brWBV'><span id='brWBV'><b id='brWBV'><form id='brWBV'><ins id='brWBV'></ins><ul id='brWBV'></ul><sub id='brWBV'></sub></form><legend id='brWBV'></legend><bdo id='brWBV'><pre id='brWBV'><center id='brWBV'></center></pre></bdo></b><th id='brWBV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='brWBV'><tfoot id='brWBV'></tfoot><dl id='brWBV'><fieldset id='brWBV'></fieldset></dl></div>

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

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

                          <tbody id='brWBV'></tbody>
                          • <legend id='brWBV'><style id='brWBV'><dir id='brWBV'><q id='brWBV'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 亚洲精色 | 婷婷色网| 99久久精品一区二区毛片吞精 | 久久精品99国产精品 | 国产超碰人人爽人人做人人爱 | 男女羞羞视频网站 | 欧美一级欧美三级在线观看 | 日韩免费高清视频 | 色呦呦网站 | 久久综合久 | 国产视频久 | 在线观看国产三级 | 国产91在线播放 | 亚洲精品电影网在线观看 | 成人免费视频观看 | 五月天婷婷综合 | 一级黄色片在线看 | 免费看a| 97视频在线免费 | 91麻豆精品国产91久久久更新资源速度超快 | 国产一级片一区二区三区 | 中文字幕av一区 | 成人精品国产免费网站 | 久久久国产精品入口麻豆 | 国产精品日日夜夜 | 黑人一级黄色大片 | 九九热精品在线 | 久久av一区 | 国产精品久久久久久亚洲调教 | 亚洲激情在线观看 | 成人av免费播放 | 午夜精品久久久久99蜜 | 国产亚洲精品美女久久久久久久久久 | 一区二区日本 | 日韩中文字幕在线观看 | 国产精品一区二区三区在线播放 | 91精品久久久久久久久久入口 | 欧洲一区二区视频 | 成人av一区 | 免费黄色大片 | 日本又色又爽又黄又高潮 |