Click or drag to resize

ZebraP12Info Class

A utility class used to extract info from certificate files and convert the contents into Zebra friendly formats.
Inheritance Hierarchy
SystemObject
  Zebra.Sdk.CertificateZebraP12Info

Namespace:  Zebra.Sdk.Certificate
Assembly:  SdkApi_Core (in SdkApi_Core.dll) Version: 2.14.1989
Syntax
public class ZebraP12Info

The ZebraP12Info type exposes the following members.

Constructors
  NameDescription
Public methodZebraP12Info
Creates a wrapper that opens up the provided certificate keystore stream.
Top
Properties
  NameDescription
Public propertyKeyStore
Gets the keystore of the processed client certificate.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetAliases
Get a list of aliases present in the certificate keystore.
Public methodGetCaCommonName
Get the common name of the CA associated with the certificate file.
Public methodGetCaCommonName(String)
Get the common name of the CA associated with the certificate file.
Public methodGetCaContent
Get the content of the ca, which is determined to be all entries in the certificate chain after the first entry.
Public methodGetCaContent(String)
Get the content of the ca, which is determined to be all entries in the certificate chain after the first entry.
Public methodGetCaExpirationDate
Get the expiration data of the CA associated with the certificate file.
Public methodGetCaExpirationDate(String)
Get the expiration data of the CA associated with the certificate file.
Public methodGetCertificateCommonName
Get the common name of the client certificate associated with the certificate file.
Public methodGetCertificateCommonName(String)
Get the common name of the client certificate associated with the certificate file.
Public methodGetCertificateContent
Get the content of the first entry in the certificate's certificate chain.
Public methodGetCertificateContent(String)
Get the content of the first entry in the certificate's certificate chain.
Public methodGetCertificateExpirationDate
Get the expiration data of the client certificate associated with the certificate file.
Public methodGetCertificateExpirationDate(String)
Get the expiration data of the client certificate associated with the certificate file.
Public methodGetCertificateIssuer
Get the issuer of the client certificate.
Public methodGetCertificateIssuer(String)
Get the issuer of the client certificate.
Public methodGetEncryptedPrivateKeyContent(String)
Get the encrypted private key content.
Public methodGetEncryptedPrivateKeyContent(String, String)
Get the encrypted private key content.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetPrivateKeyAlgorithm
Get the algorithm used by the private key.
Public methodGetPrivateKeyAlgorithm(String)
Get the algorithm used by the private key.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
using System;
using System.IO;
using System.Text;
using Zebra.Sdk.Certificate;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Printer;

public class ZebraP12InfoExample {

    public static void Main(string[] args) {

        ZebraP12Info zebraP12Info = null;
        string p12FilePassword = "P12_PASSWORD";
        string p12Alias = "entryAliasToExtract";
        string privateKeyEncryptionPassword = "1234";

        try {
            using (FileStream p12InputStream = new FileStream("/path/to/file.p12", FileMode.Open)) {
                zebraP12Info = new ZebraP12Info(p12InputStream, p12FilePassword);
            }
        } catch (FileNotFoundException) {
            Console.WriteLine("Could not find the p12 file.");
        } catch (ZebraCertificateException) {
            Console.WriteLine("Failed to extract contents from the p12 file.  Make sure the provided p12 file and password are valid.");
        }

        DriverPrinterConnection conn = null;
        try {
            string caContent = zebraP12Info.GetCaContent();
            string clientCertificateContent = zebraP12Info.GetCertificateContent();
            string encryptedPrivateKeyContent = zebraP12Info.GetEncryptedPrivateKeyContent(p12Alias, privateKeyEncryptionPassword);

            conn = new DriverPrinterConnection("myPrinterDriverName");
            conn.Open();
            ZebraPrinterLinkOs linkosPrinter = ZebraPrinterFactory.GetLinkOsPrinter(conn);

            linkosPrinter.StoreFileOnPrinter(Encoding.UTF8.GetBytes(clientCertificateContent), ZebraCertificateInfo.CLIENT_CERT_NRD_PRINTER_FILE_NAME);
            linkosPrinter.StoreFileOnPrinter(Encoding.UTF8.GetBytes(caContent), ZebraCertificateInfo.CA_CERT_NRD_PRINTER_FILE_NAME);
            linkosPrinter.StoreFileOnPrinter(Encoding.UTF8.GetBytes(encryptedPrivateKeyContent), ZebraCertificateInfo.CLIENT_PRIVATE_KEY_NRD_PRINTER_FILE_NAME);
            linkosPrinter.SetSetting("wlan.private_key_password", privateKeyEncryptionPassword);
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        } finally {
            if (conn != null) {
                conn.Close();
            }
        }
    }
}
See Also