RSA Key Container’s name limitation
In one of our projects we use a machine level key container in order to store a RSA key. The code is well tested and used in our test environment before production. But today something very strange happened. The Unit tests failed on our continuous integration server. What’s wrong? Every failed test has failed with an error as below.
System.Security.Cryptography.CryptographicException: The Keyset parameter is invalid.
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.Utils._CreateCSP(CspParameters param, Boolean randomKeyContainer, SafeProvHandle& hProv)
at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters)
At the beginning I though that it is connected with permissions or something similar but it wasn’t. I have a tool that I used to test key container name generation (I forgot to say that I use to generate the key container name dynamically). I saw that the name is too long 288 symbols. Than I’ve searched in Internet about some information about key container name length restrictions but I didn’t found. I suppose there is no such limitation.
No doubt that I do not find any information about name length I’ve decided to try to cut the lend and to test what will happen. And the problem was with the name length. With some tests I found that the max length is 260. I cannot say it is only in my case or always but it is for sure that I have this limitation.
Leave a Reply