Decode the Base64 certificate data. For example, the following Visual C# sample code decodes Base64 certificate data:
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace ReadBase64Cert
{
public class ReadBase64Cert
{
public ReadBase64Cert()
{
}
public static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Usage: Base64EncodedFile (.cer)\n");
return;
}
// args[0] - Base64Encoded .cer file
// Open the certificate, and read it into a byte array.
FileStream certFile = new FileStream(args[0],
FileMode.Open,
FileAccess.Read);
int size = (int)certFile.Length;
byte[] certBytes = new byte[size];
size = certFile.Read(certBytes, 0, size);
certFile.Close();
// Remove the unnecessary characters.
String certString = Encoding.ASCII.GetString(certBytes);
StringBuilder sb = new StringBuilder(certString);
sb.Replace("-----BEGIN CERTIFICATE-----", "");
sb.Replace("-----END CERTIFICATE-----", "");
// Decode the bytes from base64 to raw bytes.
certBytes = Convert.FromBase64String(sb.ToString());
X509Certificate cert = new X509Certificate(certBytes);
Console.WriteLine(cert.GetName());
}
}
}