该证书的SetCertificate()参数应该是什么?

时间:2017-05-25 16:06:50

标签: c# x509certificate

对于此证书,以下呼叫的参数应该是什么?我尝试了以下操作,但没有用。

X509CertificateInitiatorClientCredential.ClientCertificate.SetCertificate(
     StoreLocation.LocalMachine
    ,StoreName.CertificateAuthority
    ,X509FindType.FindBySubjectName
    ,"CN=MPCA" // also tried without CN=
);

enter image description here

1 个答案:

答案 0 :(得分:0)

证书工具的TrustedRootCertificateAuthorities商店名称映射到.NET X509 API中的StoreName.Root

X509CertificateInitiatorClientCredential.ClientCertificate.SetCertificate(
     StoreLocation.LocalMachine
    ,StoreName.Root
    ,X509FindType.FindBySerialNumber
    ,"FA###########434" // serial found by enumerating all certs
);

或者:

X509CertificateInitiatorClientCredential.ClientCertificate.SetCertificate(
     StoreLocation.LocalMachine
    ,StoreName.Root
    ,X509FindType.FindBySubjectName
    ,"MPCA" // Without CN=
);