c# - 授予用户对私钥的权限
问题描述
安装我的 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 尝试使用私钥时,它无法访问它。
查看 certlm,certificate -> All Tasks -> Manage Private Keys.. 我可以看到我的用户不在列表中。通过 GUI 添加我的用户解决了这个问题,但我需要在代码中完成!
解决方案
推荐阅读
- android - 为什么 gradle 构建过程会去掉我的 Application 和 Activity 类?
- powershell - 从数组中提供 Get-ChildItem 路径信息 - 非法字符
- c# - 有没有办法为 IIS 提供 MVC 解决方案所依赖的 DLL 的位置?
- javascript - 如何从 Storybook 中的样式组件渲染全局样式?
- google-cloud-platform - 需要说明如何使用 Terraform 管理 Google Cloud 项目
- events - Magento 2 - 事件'sales_order_place_after'的观察者不起作用
- python-3.x - 在 Python3 中同时进行 10 000 个连续 opencv 操作的最佳并发方式是什么?
- javascript - 按下联系表单中的按钮后,如何重新加载页面并清除输入值?
- javascript - 如何修复“TypeError:无法读取未定义的属性‘fn’”和“无法要求 Taiko”
- angular - 每隔 1 秒更新一次 ngFor 模板的数组