Class X509Support

java.lang.Object
zeroecho.sdk.util.X509Support

public final class X509Support extends Object
Utility class providing support for working with X.509 certificates, private keys, and certification requests using PEM-encoded files and the Bouncy Castle library.

This class includes static helper methods to:

  • Load an X.509 certificate from a PEM file
  • Load a PKCS#10 certification request (CSR) from a PEM file
  • Print a PrivateKey in PEM format
  • Print a Certificate, including its PEM-encoded form

All methods are static and the class cannot be instantiated.

Note: This class relies on the Bouncy Castle library and assumes the Bouncy Castle provider is correctly configured.

Author:
Leo Galambos
  • Method Details

    • loadCertificate

      public static Certificate loadCertificate(String path) throws IOException
      Loads an X509Certificate from a PEM file.
      Parameters:
      path - the file path to the certificate PEM file
      Returns:
      the loaded X509Certificate or null if invalid
      Throws:
      IOException - if an I/O error occurs reading the file
    • printPrivateKey

      public static void printPrivateKey(PrivateKey privKey)
      Utility method to print a PrivateKey in PEM format to standard output.

      This method writes the private key using a JcaPEMWriter and prints it to the console in PEM (Base64-encoded) format. If an error occurs during the writing process, it logs a warning.

      Parameters:
      privKey - the PrivateKey to print
    • printCertificate

      public static void printCertificate(Certificate cert)
      Prints the certificate details to standard output, including its PEM encoded representation.
      Parameters:
      cert - the Certificate to print
    • loadCSR

      public static CertificationRequest loadCSR(String path) throws IOException
      Loads a PKCS#10 Certification Request (CSR) from a PEM file.
      Parameters:
      path - the file path to the CSR PEM file
      Returns:
      the loaded CertificationRequest or null if invalid
      Throws:
      IOException - if an I/O error occurs reading the file