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) 、Authenticode 或 Secure Sockets Layer (SSL) 等功能的特定用途,可能仍然無效。 如果需要進一步處理,才能判斷憑證是否對特定原則有效,請從 X509Chain 衍生類別並覆寫 Build 方法,以便先呼叫基類 Build
方法,然後執行其他處理。