【问题标题】:Cannot Decrypt RSA encrypted Key无法解密 RSA 加密密钥
【发布时间】:2012-05-08 21:31:34
【问题描述】:

长话短说,我正在使用 DES 并使用 RSA 加密密码以进行密钥交换,密码不超过 16 个字符 问题是当我加密密钥时,加密的大小变得太大,我无法解密 这是我的 rsa 加密和解密代码:

加密:--我一直在尝试将 localpwd 作为“asd”

    byte[] plaintext = utf8.GetBytes(localpwd);
    byte[] ciphertext = rsaservice.Encrypt(plaintext, false);
    string cipherresult = Convert.ToBase64String(ciphertext);

然后我在文本框上打印加密密钥并尝试解密

    byte[] ciphertext = utf8.GetBytes(filetest.Text);
    byte[] plain = rsaservice.Decrypt(ciphertext, true);
    string plaintext = utf8.GetString(plain);

我得到“要解密的数据超过了这个 256 字节模数的最大值”。 我尝试增加密钥大小以能够加密和解密更大的密钥大小,但增加密钥只会增加加密数据的大小,从而导致相同的错误 请帮忙!!!

【问题讨论】:

  • 我没有看到ToBase64String()的反面
  • 我正在使用 utf8 编码将其转换为字节并再次转换为字符串

标签: c# security encryption rsa encryption-asymmetric


【解决方案1】:
//byte[] ciphertext = utf8.GetBytes(filetest.Text);
  byte[] ciphertext = Convert.FromBase64String(filetest.Text);

【讨论】:

  • 哇,没想到会这么简单,您先生刚刚救了我的命 :D 谢谢
  • 我可以使用 unicode 吗?我正在尝试通过网络流发送,但我无法为 Base64 字符串发送
  • 我不知道该如何感谢你
猜你喜欢
  • 2018-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-13
  • 2020-01-24
  • 2019-06-28
相关资源
最近更新 更多