c# - 如何在 c# 中列出所有带有 oid 的 Microsoft CA 证书模板
问题描述
我正在尝试检索 Microsoft CA 中的所有可注册证书模板。我可以使用 powershell 命令“Get-CATemplate”来做到这一点。我想在 c# 中做到这一点而不使用 powershell 命令
解决方案
Microsoft CA 中所有可注册证书模板的列表可以使用ICertRequest2
COM 接口检索。GetCAProperty
此接口中有一个可用的方法。
您必须添加对CertCli
COM 库的引用。
然后使用CCertRequest
实现ICertRequest
接口的类。该方法以以下格式返回字符串值:TemplateName1\nTemplateOID1\nTemplateName2\nTemplateOID2\....
您可以使用 \n 拆分此字符串。在下面的示例中,我仅选择模板名称。
private const int CR_PROP_TEMPLATES = 0x0000001D;
private const int PROPTYPE_STRING = 0x00000004;
public void GetTemplates(string CAServer)
{
try
{
var objCertRequest = new CCertRequest();
Regex regex = new Regex(@"([A-Za-z]+)");
string templateString = objCertRequest.GetCAProperty(CAServer, CR_PROP_TEMPLATES, 0, PROPTYPE_STRING, 0);
string[] templates = Regex.Split(templateString, @"\n");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
更多详情请GetCAProperty
点击这里
推荐阅读
- c# - 单击按钮时如何在我选择的位置创建游戏对象.unity 2d
- php - 如何在 json 数组中添加 while 或 foreach 循环?
- cassandra - 迁移后停用 cassandra 节点并设置了 initial_tokens
- docker - 如何找出一个worker节点对应的kubernetes主服务器?如何杀死残留的k8s容器?
- javascript - 无法使用 Angular2+ 成功测试我的 NgForm 调用
- c++ - 模板的两个指针之间的差异
- c++ - 将浮点向量转换为双精度
- android - 无法更新 Android 中的任何支持库
- python - 在python中读取json文件
- javascript - JSSOR 滑块 - 如何更改这些属性?