Location of container for public and private keys in Windows?

后端 未结 2 992
再見小時候
再見小時候 2021-02-05 22:06

I am trying to store my public and private keys in a container using following code:

CspParameters cp = new CspParameters();
cp.KeyContainerName = \"Test\";
RSAC         


        
2条回答
  •  野的像风
    2021-02-05 22:20

    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

提交回复
热议问题