简体   繁体   中英

RSACryptoServiceProvider - Decrypt - The parameter is incorrect

I need decrypt text but I am getting the message The parameter is incorrect .

The certificate is getting correctly, it is registered in 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. 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.

I'm using VS2010 with .net 4. The asp.net proyect uses IIS like server, doesn't use 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.

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. 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).

So, you shouldn't be segmenting the data variable, just feed it directly to the 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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