首页 新闻 会员 周边

RSA 加密 The data to be decrypted exceeds the maximum for this modulus of 128 bytes.

0
悬赏园豆:20 [待解决问题]

加密过程:

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的主页 Sir Chen | 初学一级 | 园豆:186
提问于:2016-07-22 16:58
< >
分享
所有回答(2)
0

http://www.xuebuyuan.com/68875.html 看看这个 或许有用

Постой! | 园豆:1084 (小虾三级) | 2016-07-22 17:08

谢谢,已经找到问题了,是dudu说的那样,在加密完之后用Base64转码一下,在解密之前在Base64反转码一下,这就可以了

支持(0) 反对(0) Sir Chen | 园豆:186 (初学一级) | 2016-07-23 11:16
0

对加密完的密文进行Base64转码一下,然后在解密之前再使用Base64反转码一下就可以了

Sir Chen | 园豆:186 (初学一级) | 2016-07-23 11:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册