Class X509CertChainUtils


  • public class X509CertChainUtils
    extends java.lang.Object
    X.509 certificate chain utilities.
    Version:
    2020-02-22
    Author:
    Vladimir Dzhuvinov
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<java.security.cert.X509Certificate> parse​(java.io.File pemFile)
      Parses a X.509 certificate chain from the specified PEM-encoded representation.
      static java.util.List<java.security.cert.X509Certificate> parse​(java.lang.String pemString)
      Parses a X.509 certificate chain from the specified PEM-encoded representation.
      static java.util.List<java.security.cert.X509Certificate> parse​(java.util.List<Base64> b64List)
      Parses a X.509 certificate chain from the specified Base64-encoded DER-encoded representation.
      static java.util.List<java.util.UUID> store​(java.security.KeyStore trustStore, java.util.List<java.security.cert.X509Certificate> certChain)
      Stores a X.509 certificate chain into the specified Java trust (key) store.
      static java.util.List<Base64> toBase64List​(java.util.List<java.lang.Object> jsonArray)
      Converts the specified JSON array of strings to a list of Base64 encoded objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toBase64List

        public static java.util.List<Base64> toBase64List​(java.util.List<java.lang.Object> jsonArray)
                                                   throws java.text.ParseException
        Converts the specified JSON array of strings to a list of Base64 encoded objects.
        Parameters:
        jsonArray - The JSON array of string, null if not specified.
        Returns:
        The Base64 list, null if not specified.
        Throws:
        java.text.ParseException - If parsing failed.
      • parse

        public static java.util.List<java.security.cert.X509Certificate> parse​(java.util.List<Base64> b64List)
                                                                        throws java.text.ParseException
        Parses a X.509 certificate chain from the specified Base64-encoded DER-encoded representation.
        Parameters:
        b64List - The Base64-encoded DER-encoded X.509 certificate chain, null if not specified.
        Returns:
        The X.509 certificate chain, null if not specified.
        Throws:
        java.text.ParseException - If parsing failed.
      • parse

        public static java.util.List<java.security.cert.X509Certificate> parse​(java.io.File pemFile)
                                                                        throws java.io.IOException,
                                                                               java.security.cert.CertificateException
        Parses a X.509 certificate chain from the specified PEM-encoded representation. PEM-encoded objects that are not X.509 certificates are ignored. Requires BouncyCastle.
        Parameters:
        pemFile - The PEM-encoded X.509 certificate chain file. Must not be null.
        Returns:
        The X.509 certificate chain, empty list if no certificates are found.
        Throws:
        java.io.IOException - On I/O exception.
        java.security.cert.CertificateException - On a certificate exception.
      • parse

        public static java.util.List<java.security.cert.X509Certificate> parse​(java.lang.String pemString)
                                                                        throws java.io.IOException,
                                                                               java.security.cert.CertificateException
        Parses a X.509 certificate chain from the specified PEM-encoded representation. PEM-encoded objects that are not X.509 certificates are ignored. Requires BouncyCastle.
        Parameters:
        pemString - The PEM-encoded X.509 certificate chain. Must not be null.
        Returns:
        The X.509 certificate chain, empty list if no certificates are found.
        Throws:
        java.io.IOException - On I/O exception.
        java.security.cert.CertificateException - On a certificate exception.
      • store

        public static java.util.List<java.util.UUID> store​(java.security.KeyStore trustStore,
                                                           java.util.List<java.security.cert.X509Certificate> certChain)
                                                    throws java.security.KeyStoreException
        Stores a X.509 certificate chain into the specified Java trust (key) store. The name (alias) for each certificate in the store is a generated UUID.
        Parameters:
        trustStore - The trust (key) store. Must be initialised and not null.
        certChain - The X.509 certificate chain. Must not be null.
        Returns:
        The UUIDs for the stored entry.
        Throws:
        java.security.KeyStoreException - On a key store exception.