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

      <bdo id='1HnpP'></bdo><ul id='1HnpP'></ul>
    <tfoot id='1HnpP'></tfoot>

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

    <small id='1HnpP'></small><noframes id='1HnpP'>

  • <legend id='1HnpP'><style id='1HnpP'><dir id='1HnpP'><q id='1HnpP'></q></dir></style></legend>

        使用 RSACryptoServiceProvider 進行公鑰加密

        Public key encryption with RSACryptoServiceProvider(使用 RSACryptoServiceProvider 進行公鑰加密)

          <tbody id='Bieoc'></tbody>
        1. <tfoot id='Bieoc'></tfoot>
          • <bdo id='Bieoc'></bdo><ul id='Bieoc'></ul>

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

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

                • 本文介紹了使用 RSACryptoServiceProvider 進行公鑰加密的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  一段時間以來,我在 CodeProject 上看過一篇文章,其中解釋了如何使用 RSA 提供程序進行加密和解密:

                  I have been over an article at CodeProject a for a while that explains how to encrypt and decrypt using the RSA provider:

                  RSA 私鑰加密

                  雖然 2009 年的舊版本有問題,但 2012 年的新版本(支持 System.Numerics.BigInteger)似乎更可靠.不過,這個版本缺少的是一種使用 public 密鑰加密 并使用 private 密鑰解密 的方法.

                  While the old version from 2009 was buggy, the new 2012 version (with System.Numerics.BigInteger support) seems more reliable. What this version lacks though is a way to encrypt with a public key and decrypt using the private key.

                  所以,我自己嘗試過,但解密時會出現垃圾.我不熟悉 RSA 提供商,所以我在這里一無所知.很難找到更多關于這應該如何工作的信息.

                  So, I tried it myself but get garbage when I decrypt. I'm not familiar with the RSA provider, so I'm in the dark here. It's hard to find more info on how this is supposed to work.

                  有人知道這有什么問題嗎?以下是使用公鑰加密:

                  // Add 4 byte padding to the data, and convert to BigInteger struct
                  BigInteger numData = GetBig( AddPadding( data ) );
                  RSAParameters rsaParams = rsa.ExportParameters( false );
                  //BigInteger D = GetBig( rsaParams.D ); //only for private key
                  BigInteger Exponent = GetBig( rsaParams.Exponent );
                  BigInteger Modulus = GetBig( rsaParams.Modulus );
                  BigInteger encData = BigInteger.ModPow( numData, Exponent, Modulus );    
                  return encData.ToByteArray();
                  

                  執行此操作時是否使用提供商提供的大D"?可能不是,因為它是沒有D"的公鑰.

                  Do I use the big "D" from the provider when I do this? Probably not since it's the public key which doesn't have the "D".

                  然后是對應的(使用 PRIVATE 密鑰解密):

                  BigInteger numEncData = new BigInteger( cipherData );
                  
                  RSAParameters rsaParams = rsa.ExportParameters( true );
                  BigInteger D = GetBig( rsaParams.D );
                  //BigInteger Exponent = GetBig( rsaParams.Exponent );
                  BigInteger Modulus = GetBig( rsaParams.Modulus );
                  
                  BigInteger decData = BigInteger.ModPow( numEncData, D, Modulus );
                  
                  byte[] data = decData.ToByteArray();
                  byte[] result = new byte[ data.Length - 1 ];
                  Array.Copy( data, result, result.Length );
                  result = RemovePadding( result );
                  
                  Array.Reverse( result );
                  return result;
                  

                  這里需要D"還是指數?

                  Do I need the "D" or the Exponent here?

                  顯然,我需要加密貨幣在私人-公共-公共-私人兩種方式下工作.非常感謝任何幫助!

                  推薦答案

                  這里有一個例子:

                      public static void rsaPlayground()
                      {
                          byte[] data = new byte[] { 1, 2, 3, 4, 5 };
                          RSACryptoServiceProvider csp = new RSACryptoServiceProvider();//make a new csp with a new keypair
                          var pub_key = csp.ExportParameters(false); // export public key
                          var priv_key = csp.ExportParameters(true); // export private key
                  
                          var encData = csp.Encrypt(data, false); // encrypt with PKCS#1_V1.5 Padding
                          var decBytes = MyRSAImpl.plainDecryptPriv(encData, priv_key); //decrypt with own BigInteger based implementation
                          var decData = decBytes.SkipWhile(x => x != 0).Skip(1).ToArray();//strip PKCS#1_V1.5 padding
                  
                      }
                  
                      public class MyRSAImpl 
                      {
                  
                          private static byte[] rsaOperation(byte[] data, BigInteger exp, BigInteger mod)
                          {
                              BigInteger bData = new BigInteger(
                                  data    //our data block
                                  .Reverse()  //BigInteger has another byte order
                                  .Concat(new byte[] { 0 }) // append 0 so we are allways handling positive numbers
                                  .ToArray() // constructor wants an array
                              );
                              return 
                                  BigInteger.ModPow(bData, exp, mod) // the RSA operation itself
                                  .ToByteArray() //make bytes from BigInteger
                                  .Reverse() // back to "normal" byte order
                                  .ToArray(); // return as byte array
                  
                              /*
                               * 
                               * A few words on Padding:
                               * 
                               * you will want to strip padding after decryption or apply before encryption 
                               * 
                               */
                          }
                  
                          public static byte[] plainEncryptPriv(byte[] data, RSAParameters key) 
                          {
                              MyRSAParams myKey = MyRSAParams.fromRSAParameters(key);
                              return rsaOperation(data, myKey.privExponent, myKey.Modulus);
                          }
                          public static byte[] plainEncryptPub(byte[] data, RSAParameters key)
                          {
                              MyRSAParams myKey = MyRSAParams.fromRSAParameters(key);
                              return rsaOperation(data, myKey.pubExponent, myKey.Modulus);
                          }
                          public static byte[] plainDecryptPriv(byte[] data, RSAParameters key)
                          {
                              MyRSAParams myKey = MyRSAParams.fromRSAParameters(key);
                              return rsaOperation(data, myKey.privExponent, myKey.Modulus);
                          }
                          public static byte[] plainDecryptPub(byte[] data, RSAParameters key)
                          {
                              MyRSAParams myKey = MyRSAParams.fromRSAParameters(key);
                              return rsaOperation(data, myKey.pubExponent, myKey.Modulus);
                          }
                  
                      }
                  
                      public class MyRSAParams
                      {
                          public static MyRSAParams fromRSAParameters(RSAParameters key)
                          {
                              var ret = new MyRSAParams();
                              ret.Modulus = new BigInteger(key.Modulus.Reverse().Concat(new byte[] { 0 }).ToArray());
                              ret.privExponent = new BigInteger(key.D.Reverse().Concat(new byte[] { 0 }).ToArray());
                              ret.pubExponent = new BigInteger(key.Exponent.Reverse().Concat(new byte[] { 0 }).ToArray());
                  
                              return ret;
                          }
                          public BigInteger Modulus;
                          public BigInteger privExponent;
                          public BigInteger pubExponent;
                      }
                  

                  這篇關于使用 RSACryptoServiceProvider 進行公鑰加密的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                    <tbody id='WB6Gi'></tbody>
                • <i id='WB6Gi'><tr id='WB6Gi'><dt id='WB6Gi'><q id='WB6Gi'><span id='WB6Gi'><b id='WB6Gi'><form id='WB6Gi'><ins id='WB6Gi'></ins><ul id='WB6Gi'></ul><sub id='WB6Gi'></sub></form><legend id='WB6Gi'></legend><bdo id='WB6Gi'><pre id='WB6Gi'><center id='WB6Gi'></center></pre></bdo></b><th id='WB6Gi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WB6Gi'><tfoot id='WB6Gi'></tfoot><dl id='WB6Gi'><fieldset id='WB6Gi'></fieldset></dl></div>
                • <legend id='WB6Gi'><style id='WB6Gi'><dir id='WB6Gi'><q id='WB6Gi'></q></dir></style></legend>
                  • <small id='WB6Gi'></small><noframes id='WB6Gi'>

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

                        <tfoot id='WB6Gi'></tfoot>

                            主站蜘蛛池模板: 91久久精品国产 | 正在播放国产精品 | 成人免费视频观看视频 | 久久大陆 | 国产欧美一区二区三区在线看 | 亚洲精品视频网站在线观看 | 91毛片在线观看 | 亚洲免费在线视频 | av片网站| 精品中文视频 | 国产精品久久久久久久久久 | 亚洲一区二区三区视频免费观看 | 成人不卡在线 | 欧美极品一区二区 | 亚洲视频一区二区三区四区 | 久久久国产网站 | 精品中文字幕一区二区 | 亚洲福利av | 国产成人免费在线观看 | 亚洲成人国产精品 | 日本三级在线 | 91久久久久久久 | 久久久久久久久久久久久9999 | 亚洲免费av一区 | 免费在线一区二区三区 | 成人亚洲性情网站www在线观看 | 成人九色 | 女同久久另类99精品国产 | 精品成人在线观看 | 欧美日韩三区 | 精品久久久久久久久久久久 | chengrenzaixian| 国产精品久久久久久久白浊 | 国产一区二区三区四区五区3d | 中文字幕一区二区三区在线观看 | 中文字幕 国产精品 | 99精品免费在线观看 | 久久激情视频 | 天天操天天射综合网 | 日韩精品1区2区 | 最新日韩在线 |