3

Here is my code:

        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(128);

        try
        {              
            string publicKeyXML = rsa.ToXmlString(false);
            string privateKeyXML = rsa.ToXmlString(true);
            int size = rsa.KeySize;
        }
        finally 
        {
            rsa.PersistKeyInCsp = false;
        }

I just keep getting the same error "Invalid flags specified". If I use the no-argument constructor, no exception is thrown and the keysize is 1024.

coffeeak
  • 2,980
  • 7
  • 44
  • 87
  • I assume .net doesn't support 128 bit RSA. Perhaps because such small RSA keys are utterly insecure. Or perhaps because RSA padding is larger than this for typical hashes. 512 bit RSA keys are very weak, the recommended minimum are 1024 bits, and even that isn't very strong. – CodesInChaos Dec 21 '12 at 10:28
  • @CodesInChaos: Thanks! You were right. I just found the answer on MSDN! – coffeeak Dec 21 '12 at 10:33
  • I was looking at the documentation for the constructor and didn't find that statement. – CodesInChaos Dec 21 '12 at 10:40
  • Thanks for editing. I did not paste the right link :P – coffeeak Dec 21 '12 at 10:50

1 Answers1

7

RSACryptoServiceProvider does not support 128 bit keys:

The RSACryptoServiceProvider supports key lengths from 384 bits to 16384 bits in increments of 8 bits

Quoted from MSDN - RSACryptoServiceProvider.KeySize Property

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
coffeeak
  • 2,980
  • 7
  • 44
  • 87