授予私钥用户权限

问题描述 投票:0回答:1

安装我的WCF服务,我也安装带有私钥的证书。由于我将以其他用户身份运行服务,因此该用户需要访问私钥。我广泛阅读了其他stackoverflow问题,它们都建议需要调整文件系统中私钥文件的权限。我这样做是,

        private static void AddUserPermissions(X509Certificate2 certificate, NTAccount user, StoreLocation storeLocation)
        {
            RSACryptoServiceProvider rsaProvider = (RSACryptoServiceProvider)certificate.PrivateKey;

            // Find file 
            string keyPath = FindKeyLocation(rsaProvider.CspKeyContainerInfo.UniqueKeyContainerName, storeLocation);
            FileInfo keyFileInfo = new FileInfo(keyPath);

            // Create new FileSecurity
            FileSecurity keyFileSecurity = keyFileInfo.GetAccessControl();
            keyFileSecurity.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.Read, AccessControlType.Allow));

            // Apply file security to the file
            keyFileInfo.SetAccessControl(keyFileSecurity);
        }

[运行程序并检查私钥文件时,我可以看到,例如,“网络服务”已添加到权限列表中。

很好,正在工作,但是当WCF尝试使用私钥时,它无法访问它。

查看证书,证书->所有任务->管理私钥。我可以看到我的用户不在列表中。通过GUI添加我的用户可以解决此问题,但我需要通过代码来完成!!

c# windows file certificate x509certificate
1个回答
0
投票

加密服务提供者(Microsoft RSA SChannel加密提供者)

这些键位于C:\ProgramData\Application Data\Microsoft\Crypto\RSA\MachineKeys中,并且在此处设置普通文件权限反映在certlm.msc中。

CSP

下一代加密货币(Microsoft密钥存储提供程序)

这些键位于C:\ProgramData\Application Data\Microsoft\Crypto\Keys中,并且在此处设置普通文件权限反映在certlm.msc中。

CNG

摘要

确保您在正确的位置修改了正确文件的权限。

© www.soinside.com 2019 - 2024. All rights reserved.