How to set read permission on the private key file of X.509 certificate from .NET

前端 未结 6 1357
遥遥无期
遥遥无期 2020-11-28 07:12

Here is the code to add a pfx to the Cert store.

X509Store store = new X509Store( StoreName.My, StoreLocation.LocalMachine );
store.Open( OpenFlags.ReadWrite         


        
6条回答
  •  醉梦人生
    2020-11-28 07:47

    You can use the WinHttpCertCfg.exe tool that ships as part of the Windows Server 2003 Resource Kit Tools.

    Example:

    winhttpcertcfg -g -c LOCAL_MACHINE\My -s test -a NetworkService
    


    Alternatively, you could use the Find Private Key tool that ships with the WCF SDK, to find the location on disk of the certificate's private key file. Then you can simply use ACL to set the right privileges on the file.

    Example:

    FindPrivateKey My LocalMachine -n "CN=test"
    

提交回复
热议问题