I have created a customer RSA key container (for encrypting connection string in web.config) using the following command:
aspnet_regiis -pc “TestKeys” -size 2048 -exp
I then exported the key to an xml file and used it to initialise an instance of RSACryptoServiceProvider so that I could check the key size was 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());
}
It seems that aspnet_regiis is ignoring the -size argument. Am I missing something?
Also, is there a recommended key size for encrypting .Net config sections using RSA?
I ended up using the RSACryptoServiceProvider class to create the key container as it creates the keys with the size specified.
NIST receommend a key size of 3072 bits for security required beyond 2030.
Recommendations for key management – see Table 4.