MailBee.NET Objects 4.0

Certificate.RawData Property

Gets the raw X.509 certificate data as a byte array.

public byte[] RawData {get;}

Property Value

The certificate as an array of bytes.

Example

This sample selects the first certificate from the system store called "MY" ("Personal" tab of Certificates dialog in Internet Explorer) and saves the certificate raw data into the specified file to disk.

Note    To save the certificate to disk, this sample uses standard binary writer for demonstration purposes only. The developer can call the SaveToFile method to save the certificate to disk.
[C#]
// To use the code below, import MailBee namespace at the top of your code.
using System.IO;
using MailBee.Security;

// The actual code (put it into a method of your class).
CertificateStore store = new CertificateStore(CertificateStore.Personal, CertStoreType.System, null);
CertificateCollection collection = store.GetAllCertificates();
if (collection.Count > 0)
{
    Certificate cert = collection[0];
    using (BinaryWriter bw = new BinaryWriter(File.Open(@"C:\Temp\newcert.cer", FileMode.Create)))
    {
        bw.Write(cert.RawData);
        bw.Flush();
    }
}
[Visual Basic]
' To use the code below, import MailBee namespace at the top of your code.
Imports System.IO
Imports MailBee.Security

' The actual code (put it into a method of your class).
Dim store As CertificateStore = New CertificateStore(CertificateStore.Personal, CertStoreType.System, Nothing)
Dim collection As CertificateCollection = store.GetAllCertificates()

If collection.Count > 0 Then
    Dim cert As Certificate = collection(0)
    Dim bw As New BinaryWriter(File.Open("C:\Temp\newcert.cer", FileMode.Create))

    bw.Write(cert.RawData)
    bw.Flush()
End If

See Also

Certificate Class | MailBee.Security Namespace | X509Certificate