Search code examples
c#rsarsacryptoserviceprovider

.NET: puzzling cryptographic exception in RsaCryptoServiceProvider


I get a cryptographic exception in the following code, and the exception states: invalid flags specified

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider((int)strength);
rsa.Encrypt(new byte[] { 0, 1, 2, 3, 4, 5, 7 }, false); // forcing the key to generate

I have tried to set cspParameters but there is no difference. I think it only happens when I set a large bitsize. (strength value)


Solution

  • Never mind, the source of the problem was that I set it to a value larger than 16384. (which is the max bitsize for RSA in dot net).