Display X509 certificatie information in C#

Display information about a X509 certificate with this little C# fragment:

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

class App
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Usage: Viewcert .cer");
return;
}

X509Certificate x509 = X509Certificate.CreateFromCertFile(args[0]);

Console.WriteLine(
"Issued to {0}nIssued by {1}nSerial# {2}n"
+ "From {3} To {4}nAlgo {5} Params {6}n"
+ "Format {7}n"
+ "Cert Hashn{8}nCert Datan{9}nPublic Keyn{10}",
x509.Subject, x509.Issuer, x509.GetSerialNumberString(),
x509.GetEffectiveDateString(), x509.GetExpirationDateString(),
x509.GetKeyAlgorithm(), x509.GetKeyAlgorithmParametersString(),
x509.GetFormat(), x509.GetCertHashString(), x509.GetRawCertDataString(),
x509.GetPublicKeyString());
}
}
Share

Leave a Reply

Your email address will not be published. Required fields are marked *