I am trying to store my public and private keys in a container using following code:
CspParameters cp = new CspParameters();
cp.KeyContainerName = "Test";
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
What I'd like to know is the location of the container. Is the location of the container in the file system?
If someone search for "where" the key container is stored, then the short answer is on the system. It is a series of folders starting at C:\ProgramData\Microsoft\Crypto. Depending on the key type being used and the access level (machine or user), it will be placed in its respective folder.
Private keys can be stored using a hardware wallet that uses smartcards or USB devices to generate and secure private keys offline. The private keys can also be stored using a hardware wallet that uses smartcards or USB devices to generate and secure private keys offline.
You'll find the key files in the following directory (*):
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
@"Microsoft\Crypto\RSA\MachineKeys")
You can get the filename for a given key as follows:
CspParameters cp = ...;
CspKeyContainerInfo info = new CspKeyContainerInfo(cp);
string fileName = info.UniqueKeyContainerName;
I don't believe this information is documented, so if you use it you'll be relying on undocumented implementation details which may not work in future versions of Windows. Unfortunately, it's sometimes necessary to use it; for example as noted in this question, I don't think there's any other reliable way to view permissions for an RSA Key Container from a non-privileged account.
(*) that's for machine keys. User-specific keys are presumably under Environment.SpecialFolder.LocalApplicationData
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With