Partilhar via


X509Chain.Build(X509Certificate2) Método

Definição

Cria uma cadeia X.509 usando a política especificada no X509ChainPolicy.

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

Parâmetros

certificate
X509Certificate2

Um objeto X509Certificate2.

Retornos

true se o certificado x. 509 for válido; caso contrário, false.

Atributos

Exceções

O certificate não é um certificado válido ou é null.

O certificate é ilegível.

Exemplos

O exemplo de código a seguir abre o repositório de certificados pessoal do usuário atual, permite que você selecione um certificado e, em seguida, grava informações de certificado e cadeia de certificados no console. A saída depende do certificado selecionado.

//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)

Comentários

Observe que um certificado X.509 válido de um emissor confiável é válido apenas para o uso especificado no X509ChainPolicy objeto . Certificados que atendem a essas regras de política de cadeia ainda podem ser inválidos para usos específicos com recursos como Segurança/MIME (SMIME), Authenticode ou SSL (Secure Sockets Layer). Se for necessário processamento adicional para determinar se o certificado é válido para uma política específica, derive uma classe de X509Chain e substitua o Build método para que ele chame o método de classe Build base primeiro e, em seguida, faça o processamento adicional.

Aplica-se a