简体   繁体   English

RSACryptoServiceProvider - 解密 - 参数不正确

[英]RSACryptoServiceProvider - Decrypt - The parameter is incorrect

I need decrypt text but I am getting the message The parameter is incorrect . 我需要解密文本,但我收到消息The parameter is incorrect

The certificate is getting correctly, it is registered in windows. 证书正确,它在Windows中注册。

在此输入图像描述

在此输入图像描述

Searching about the problem, I can read comment that suggest change the user in the application pool assigned to the web site in the IIS. 搜索问题,我可以阅读建议更改分配给IIS中的网站的应用程序池中的用户的注释。 I tried it but not work. 我试了但不行。

In the second image shows the size calculation, but I don't sure because subtract 11 to the KeySize divition per 8. 在第二个图像显示大小计算,但我不确定因为每8减去KeySize分区11。

I'm using VS2010 with .net 4. The asp.net proyect uses IIS like server, doesn't use Visual Studio Development Server 我正在使用VS2010和.net 4. asp.net proyect使用IIS之类的服务器,不使用Visual Studio Development Server

What can I try to solve the problem? 我可以尝试解决这个问题?

[SOLUTION] [解]

The encrypted text assigned in Decrypt method was generated with a certificate obsolete. 在Decrypt方法中分配的加密文本是在证书过时的情况下生成的。

The text was encrypted with a certificate but then it was changed, when tried decrypt the encripted text with other certificate the method fails. 文本使用证书加密但随后更改,当尝试使用其他证书解密带有文本的文本时,该方法失败。

When encrypting data using an asymmetric cryptosystem (ie RSA in your case), the size of the output is the same as the modulus size. 使用非对称密码系统(即您的情况下为RSA)加密数据时,输出的大小与模数大小相同。 In addition, the size of the input must be less than or equals the modulus size. 此外,输入的大小必须小于或等于模数大小。 Therefore when you try to decrypt a cipher text, the size of the cipher text must equal the size of the modulus (ie 128 bytes in your case since the key size is 1024 bits). 因此,当您尝试解密密文时,密文的大小必须等于模数的大小(即,因为密钥大小为1024位,所以大小写为128字节)。

So, you shouldn't be segmenting the data variable, just feed it directly to the RSACryptoServiceProvider.Decrypt . 因此,您不应该对data变量进行分段,只需将其直接提供给RSACryptoServiceProvider.Decrypt

Another thing to try is to supply true for the fOAEP parameter in the rsa.Decrypt since decrypting an OAEP padded cipher text with fOAEP set to false will cause the The parameter is incorrect exception to be thrown. 尝试另一件事是提供truefOAEP在参数rsa.Decrypt因为解密OAEP填充密文与fOAEP设置为false将导致The parameter is incorrect抛出异常。

如果更改了私钥或公钥,则会发生此异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM