.NET RSA Encryption: Minimum keysize?
I can load a 128bit RSA key in .NET, and use it for decryption. But I开发者_运维知识库 cannot seem to generate 128bit (or lower) keys, i always get the error 'Invalid flags specified'. When I try 512bits as keysize, everything works fine. So is 512bits the minimum keysize for .NET?
512 bits is (technically) a minimum size of RSA key, but it's not secure. Nowadays 1024 bits are the absolute minimum and 2048 bits are recommended.
Note, that 1024 bits in RSA corresponds in security level to 128 bits of symmetric algorithm. Maybe you confused these values, thinking that 128 bits are the same for asymmetric and symmstric encryption, but no, they aren't.
Each AsymmetricAlgorithm and SymmetricAlgorithm has a property LegalKeySizes that can help you determine if a key size is valid for the algorithm. From the links you can print out the valid key sizes for the algorithm you are using:
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
for (int i = 0; i < rsa.LegalKeySizes.Length; i++)
{
KeySizes key_size = rsa.LegalKeySizes[i];
Console.WriteLine(String.Format("[Key Size {0}] - min: {1}, max: {2}, step: {2}",
i, key_size.MinSize, key_size.MaxSize, key_size.SkipSize));
}
For RSACryptoServiceProvider, this will print:
[Key Size 0] - min: 384, max: 16384, step: 16384
精彩评论