Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of container for public and private keys in Windows?

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?

like image 651
Thabo Avatar asked May 21 '12 17:05

Thabo


People also ask

Where are key containers stored?

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.

Where does the private key get stored?

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.


1 Answers

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

like image 57
Joe Avatar answered Nov 03 '22 04:11

Joe