X509Certificate.GetPublicKeyString 方法

定義

傳回做為十六進位字串的 X.509v3 憑證公開金鑰。Returns the public key for the X.509v3 certificate as a hexadecimal string.

public:
 virtual System::String ^ GetPublicKeyString();
public virtual string GetPublicKeyString ();
abstract member GetPublicKeyString : unit -> string
override this.GetPublicKeyString : unit -> string
Public Overridable Function GetPublicKeyString () As String

傳回

String

做為十六進位字串的 X.509 憑證公開金鑰。The public key for the X.509 certificate as a hexadecimal string.

範例

下列範例會使用 GetPublicKeyString 方法,以字串形式傳回憑證的公開金鑰,並將它顯示在主控台中。The following example uses the GetPublicKeyString method to return a certificate's public key as a string and displays it to the console.

using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
   
   // The path to the certificate.
   String^ Certificate = "Certificate.cer";
   
   // Load the certificate into an X509Certificate object.
   X509Certificate^ cert = X509Certificate::CreateFromCertFile( Certificate );
   
   // Get the value.
   String^ results = cert->GetPublicKeyString();
   
   // Display the value to the console.
   Console::WriteLine( results );
}


using System;
using System.Security.Cryptography.X509Certificates;

public class X509
{

    public static void Main()
    {

        // The path to the certificate.
        string Certificate =  "Certificate.cer";

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

        // Get the value.
        string results = cert.GetPublicKeyString();

        // Display the value to the console.
        Console.WriteLine(results);
    }
}
Imports System.Security.Cryptography.X509Certificates




Public Class X509
   
   
   Public Shared Sub Main()
      
      ' The path to the certificate.
      Dim Certificate As String = "Certificate.cer"
      
      ' Load the certificate into an X509Certificate object.
      Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(Certificate)
      
      ' Get the value.
      Dim results As String = cert.GetPublicKeyString()
      
      ' Display the value to the console.
      Console.WriteLine(results)
   End Sub  
End Class  

備註

此值對應于 subjectPublicKey 憑證內 SubjectPublicKeyInfo 資料的欄位內容。This value corresponds to the contents of the subjectPublicKey field of the SubjectPublicKeyInfo data within the certificate.

適用於