首页 > 解决方案 > 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#winformsencryptioncryptographyrsa

解决方案


推荐阅读