c# - RSA Decryption C# 要解密的数据超过了这个模数的最大值 256 字节
问题描述
我试图解密字符串格式的加密数据,因此我必须执行 Encoding 函数 2 次,这导致我出现这个错误要解密的数据超过了这个 256 字节模数的最大值。但是,如果我以字节格式传入加密数据,则解密工作。
这是问题所在,我希望用户将加密数据复制并粘贴到文本框(字符串格式)中,并使用文本框中的信息进行解密。
请告诉我如何解决这个问题。
这是我的代码
public static byte[] RSADecrypt2(byte[] ciphertext, string srcKey)
{
byte[] decryptedData;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(srcKey);
decryptedData = rsa.Decrypt(ciphertext, true);
rsa.Dispose();
return decryptedData;
}
private void RSADecrypt_Click(object sender, EventArgs e)
{
byte[] encryption = Encoding.Unicode.GetBytes(passBox.Text);
string privateKey = rsaBoxPrivate.Text;
byte[] decryption = RSADecrypt2(encryption, privateKey);
decryptedBox.Text = Encoding.Unicode.GetString(decryption);
}
解决方案
推荐阅读
- c# - 如何在 c# selenium chromedriver 中选择下拉列表的下拉值而不选择?
- r - 如何将每年从原始单独文件附加到新的合并数据集
- c# - 如何使用 Caliburn Micro ActivateItem 等待并从 ViewModel 获取返回值
- python - 如何计算python中多列中2列的协方差?
- docker - 安装了 repo 的 docker-ce 未显示在 `yum list available` 中
- c# - 新手:创建 enum.FirstOrDefault(),得到“无法隐式转换类型”
- python-3.x - 我是 python 新手,我正在尝试构建一个简单的井字游戏。当我从用户那里获取输入时,它会进入无限循环
- javascript - 使用 sequelize 从两个模型表中获取数据
- c++ - 如何从键盘调用枚举器?
- maven - spring boot Maven打包时如何修改配置文件名,如config.xml xml。重新配置。XML