I created the RSA client key container (to encrypt the connection string in web.config) using the following command:
aspnet_regiis -pc "TestKeys" -size 2048 -exp
Then I exported the key to the xml file and used it to initialize the RSACryptoServiceProvider instance, so that I could check the key size, definitely 2048. However, using the code below, the key size is displayed as 1024.
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { using (FileStream fs = new FileStream(@"C:\TestKeys.xml", FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { rsa.FromXmlString(sr.ReadToEnd()); } } Console.WriteLine(rsa.KeySize.ToString()); }
Aspnet_regiis seems to be ignoring the -size argument. Did I miss something?
Also, is there a recommended key size for encrypting .Net configuration sections using RSA?
Matt f
source share