X509Chain.Build(X509Certificate2) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用 X509ChainPolicy 所指定的策略生成 X.509 链。
public:
bool Build(System::Security::Cryptography::X509Certificates::X509Certificate2 ^ certificate);
public bool Build (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public bool Build (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);
member this.Build : System.Security.Cryptography.X509Certificates.X509Certificate2 -> bool
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Build : System.Security.Cryptography.X509Certificates.X509Certificate2 -> bool
Public Function Build (certificate As X509Certificate2) As Boolean
参数
- certificate
- X509Certificate2
一个 X509Certificate2 对象。
返回
如果 X.509 证书有效,则为 true
;否则为 false
。
- 属性
例外
certificate
不是有效的证书,或者为 null
。
certificate
不可读。
示例
下面的代码示例打开当前用户的个人证书存储区,允许你选择证书,然后将证书和证书链信息写入控制台。 输出取决于所选证书。
//Output chain information of the selected certificate.
X509Chain ^ ch = gcnew X509Chain;
ch->ChainPolicy->RevocationMode = X509RevocationMode::Online;
ch->Build( certificate );
Console::WriteLine( "Chain Information" );
Console::WriteLine( "Chain revocation flag: {0}", ch->ChainPolicy->RevocationFlag );
Console::WriteLine( "Chain revocation mode: {0}", ch->ChainPolicy->RevocationMode );
Console::WriteLine( "Chain verification flag: {0}", ch->ChainPolicy->VerificationFlags );
Console::WriteLine( "Chain verification time: {0}", ch->ChainPolicy->VerificationTime );
Console::WriteLine( "Chain status length: {0}", ch->ChainStatus->Length );
Console::WriteLine( "Chain application policy count: {0}", ch->ChainPolicy->ApplicationPolicy->Count );
Console::WriteLine( "Chain certificate policy count: {0} {1}", ch->ChainPolicy->CertificatePolicy->Count, Environment::NewLine );
//Output chain information of the selected certificate.
X509Chain ch = new X509Chain();
ch.ChainPolicy.RevocationMode = X509RevocationMode.Online;
ch.Build (certificate);
Console.WriteLine ("Chain Information");
Console.WriteLine ("Chain revocation flag: {0}", ch.ChainPolicy.RevocationFlag);
Console.WriteLine ("Chain revocation mode: {0}", ch.ChainPolicy.RevocationMode);
Console.WriteLine ("Chain verification flag: {0}", ch.ChainPolicy.VerificationFlags);
Console.WriteLine ("Chain verification time: {0}", ch.ChainPolicy.VerificationTime);
Console.WriteLine ("Chain status length: {0}", ch.ChainStatus.Length);
Console.WriteLine ("Chain application policy count: {0}", ch.ChainPolicy.ApplicationPolicy.Count);
Console.WriteLine ("Chain certificate policy count: {0} {1}", ch.ChainPolicy.CertificatePolicy.Count, Environment.NewLine);
'Output chain information of the selected certificate.
Dim ch As New X509Chain()
ch.ChainPolicy.RevocationMode = X509RevocationMode.Online
ch.Build(certificate)
Console.WriteLine("Chain Information")
Console.WriteLine("Chain revocation flag: {0}", ch.ChainPolicy.RevocationFlag)
Console.WriteLine("Chain revocation mode: {0}", ch.ChainPolicy.RevocationMode)
Console.WriteLine("Chain verification flag: {0}", ch.ChainPolicy.VerificationFlags)
Console.WriteLine("Chain verification time: {0}", ch.ChainPolicy.VerificationTime)
Console.WriteLine("Chain status length: {0}", ch.ChainStatus.Length)
Console.WriteLine("Chain application policy count: {0}", ch.ChainPolicy.ApplicationPolicy.Count)
Console.WriteLine("Chain certificate policy count: {0} {1}", ch.ChainPolicy.CertificatePolicy.Count, Environment.NewLine)
注解
请注意,来自受信任颁发者的有效 X.509 证书仅对对象中指定的 X509ChainPolicy 使用有效。 对于安全/MIME (SMIME) 、验证码或安全套接字层 (SSL) 等功能,满足这些链策略规则的证书可能仍然无效。 如果需要进一步处理以确定证书是否对特定策略有效,请从 X509Chain 该方法派生类并重写该方法 Build ,以便先调用基类 Build
方法,然后执行其他处理。