首页新闻找找看学习计划

The data to be decrypted exceeds the maximum for this modulus of 128 bytes

0
悬赏园豆:10 [已解决问题] 解决于 2015-03-31 18:32

在C#中使用RSACryptoServiceProvider时,出现下面的错误:

The data to be decrypted exceeds the maximum for this modulus of 128 bytes

私钥在mac下用openssl命令生成的:

openssl genrsa -out rsa_1024_priv.pem 1024
C#
dudu的主页 dudu | 高人七级 | 园豆:38650
提问于:2015-03-31 18:24
< >
分享
最佳答案
0

对密文进行base64解码后,问题解决。

System.Convert.FromBase64String(cipherText);
dudu | 高人七级 |园豆:38650 | 2015-03-31 18:31

你好!请问这个是指生成的秘钥吗

Sir Chen | 园豆:186 (初学一级) | 2016-07-22 12:24

@Sir Chen: 不是秘钥,是加密后的文本

dudu | 园豆:38650 (高人七级) | 2016-07-22 13:14

@dudu: 在解密的时候是否要想法的操作

Sir Chen | 园豆:186 (初学一级) | 2016-07-22 14:40

@dudu: 

加密过程:

private byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
        {
            byte[] encryptedData;
            //Create a new instance of RSACryptoServiceProvider.
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {

                //Import the RSA Key information. This only needs
                //toinclude the public key information.
                RSA.ImportParameters(RSAKeyInfo);

                //Encrypt the passed byte array and specify OAEP padding.  
                //OAEP padding is only available on Microsoft Windows XP or
                //later.  
                encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
            }
            return encryptedData;
        }

 

解密过程:

/// <summary>
        ///
        /// 私钥解密
        /// </summary>
        /// <param name="DataToDecrypt"></param>
        /// <param name="RSAKeyInfo"></param>
        /// <param name="DoOAEPPadding"></param>
        /// <returns></returns>
        private byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
        {
            byte[] decryptedData;

            //Create a new instance of RSACryptoServiceProvider.
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                //Import the RSA Key information. This needs
                //to include the private key information.
                RSA.ImportParameters(RSAKeyInfo);
                //Decrypt the passed byte array and specify OAEP padding.  
                //OAEP padding is only available on Microsoft Windows XP or
                //later.  
                decryptedData = RSA.Decrypt(DataToDecrypt, DoOAEPPadding);
            }
            return decryptedData;
        }

 

然后在解密的时候就出现了,所以这便想请教一下如何解决

Sir Chen | 园豆:186 (初学一级) | 2016-07-22 16:29
其他回答(1)
0

有qq吗?可以详细问一下吗

Sir Chen | 园豆:186 (初学一级) | 2016-07-22 14:16

建议在博问中提问

支持(0) 反对(0) dudu | 园豆:38650 (高人七级) | 2016-07-22 14:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册