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

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

      1. .net 中的混合密码系统实现.错误 指定的密钥不是

        时间:2023-06-02
          <tfoot id='bqrxG'></tfoot>
            <tbody id='bqrxG'></tbody>
          • <small id='bqrxG'></small><noframes id='bqrxG'>

          • <legend id='bqrxG'><style id='bqrxG'><dir id='bqrxG'><q id='bqrxG'></q></dir></style></legend>
                  <bdo id='bqrxG'></bdo><ul id='bqrxG'></ul>
                  <i id='bqrxG'><tr id='bqrxG'><dt id='bqrxG'><q id='bqrxG'><span id='bqrxG'><b id='bqrxG'><form id='bqrxG'><ins id='bqrxG'></ins><ul id='bqrxG'></ul><sub id='bqrxG'></sub></form><legend id='bqrxG'></legend><bdo id='bqrxG'><pre id='bqrxG'><center id='bqrxG'></center></pre></bdo></b><th id='bqrxG'></th></span></q></dt></tr></i><div id='bqrxG'><tfoot id='bqrxG'></tfoot><dl id='bqrxG'><fieldset id='bqrxG'></fieldset></dl></div>
                  本文介绍了.net 中的混合密码系统实现.错误 指定的密钥不是此算法的有效大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试实现 https://en.wikipedia.org/wiki 中提到的混合密码系统/Hybrid_cryptosystem

                  目前我已经实现了以下算法

                  At the moment I have implemented following algorithm

                  private void button1_Click(object sender, EventArgs e)
                          {
                              CspParameters cspParams = new CspParameters { ProviderType = 1 };
                              RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(1024, cspParams);
                              string publicKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(false));
                              string privateKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(true));
                              string symmericKey = "Kamran12";
                              txtEncryptedData.Text = EncryptData(txtInputData.Text, symmericKey);
                              string encryptedsymmetrickey = EncryptData(symmericKey, publicKey); //error line
                              //string decryptsymmetrickey = encryptedsymmetrickey + privateKey;
                  
                              //string decrypteddata = encryptedData + decryptsymmetrickey;
                  
                          }
                  
                          public string EncryptData(string data, string key)
                          {
                              string encryptedData = null;
                  
                              byte[] buffer = Encoding.UTF8.GetBytes(data);
                  
                              DESCryptoServiceProvider desCryptSrvckey = new DESCryptoServiceProvider
                              {
                                  Key = new UTF8Encoding().GetBytes(key)
                              };
                              desCryptSrvckey.IV = desCryptSrvckey.Key;
                  
                              using (MemoryStream stmCipherText = new MemoryStream())
                              {
                                  using (CryptoStream cs = new CryptoStream(stmCipherText, desCryptSrvckey.CreateEncryptor(), CryptoStreamMode.Write))
                                  {
                                      cs.Write(buffer, 0, buffer.Length);
                                      cs.FlushFinalBlock();
                  
                  
                                      encryptedData = Encoding.UTF8.GetString(stmCipherText.ToArray());
                                  }
                              }
                              return encryptedData;
                          }
                  

                  但收到错误指定的密钥不是此算法的有效大小.在加密对称密钥时

                  But getting error Specified key is not a valid size for this algorithm. at the time of encrypting the symmetric key

                  推荐答案

                  您正在尝试使用带有 RSA 公钥的(不安全的)DES 算法进行加密.这总是会失败,DESCryptoServiceProvider 不接受 RSA 密钥.为此,您需要一个 RSACryptoServiceProvider.

                  You are trying to encrypt using the (insecure) DES algorithm with an RSA public key. That's always going to fail, DESCryptoServiceProvider doesn't accept RSA keys. You'd need an RSACryptoServiceProvider for that.

                  您可能需要考虑使用已经实现混合加密(PGP、CMS 或其中一种专有协议)的特定库.您的解决方案最终可能会运行,但它是安全的.

                  You may want to consider using a specific library that already implements hybrid cryptography (PGP, CMS or one of the proprietary protocols). The way you are going at it your solution may run in the end, but it will not be secure.

                  这篇关于.net 中的混合密码系统实现.错误 指定的密钥不是此算法的有效大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 C# 中加载 ASN.1/DER 编码的 RSA 密钥对 下一篇:如何在 C# 中获得与 PHP 单元测试相同的 HMAC256 结

                  相关文章

                  最新文章

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

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

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

                    1. <legend id='pvd7O'><style id='pvd7O'><dir id='pvd7O'><q id='pvd7O'></q></dir></style></legend>