Class CertificateLoadUtil


  • public final class CertificateLoadUtil
    extends java.lang.Object
    Contains various security-related utility methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.apache.commons.logging.Log logger  
      private static java.lang.String provider  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CertificateLoadUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static java.security.cert.CertificateFactory getCertificateFactory()
      Returns appropriate CertificateFactory.
      static java.util.Collection<java.security.cert.X509Certificate> getTrustedCertificates​(java.security.KeyStore keyStore, java.security.cert.X509CertSelector selector)  
      static void init()
      A no-op function that can be used to force the class to load and initialize.
      static java.security.cert.X509Certificate loadCertificate​(java.io.InputStream in)
      Loads a X509 certificate from the specified input stream.
      static java.security.cert.X509Certificate loadCertificate​(java.lang.String file)
      Loads an X.509 certificate from the specified file.
      static java.security.cert.X509Certificate[] loadCertificates​(java.lang.String file)
      Loads multiple X.509 certificates from the specified file.
      static java.security.cert.X509CRL loadCrl​(java.io.InputStream in)  
      static java.security.cert.X509CRL loadCrl​(java.lang.String file)  
      static java.security.cert.X509Certificate readCertificate​(java.io.BufferedReader reader)
      Loads a X.509 certificate from the specified reader.
      static void setProvider​(java.lang.String providerName)
      Sets a provider name to use for loading certificates and for generating key pairs.
      • Methods inherited from class java.lang.Object

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

      • logger

        private static org.apache.commons.logging.Log logger
      • provider

        private static java.lang.String provider
    • Constructor Detail

      • CertificateLoadUtil

        private CertificateLoadUtil()
    • Method Detail

      • init

        public static void init()
        A no-op function that can be used to force the class to load and initialize.
      • setProvider

        public static void setProvider​(java.lang.String providerName)
        Sets a provider name to use for loading certificates and for generating key pairs.
        Parameters:
        providerName - provider name to use.
      • getCertificateFactory

        protected static java.security.cert.CertificateFactory getCertificateFactory()
                                                                              throws java.security.GeneralSecurityException
        Returns appropriate CertificateFactory. If provider was set a provider-specific CertificateFactory will be used. Otherwise, a default CertificateFactory will be used.
        Returns:
        CertificateFactory
        Throws:
        java.security.GeneralSecurityException
      • loadCertificate

        public static java.security.cert.X509Certificate loadCertificate​(java.io.InputStream in)
                                                                  throws java.security.GeneralSecurityException
        Loads a X509 certificate from the specified input stream. Input stream must contain DER-encoded certificate.
        Parameters:
        in - the input stream to read the certificate from.
        Returns:
        X509Certificate the loaded certificate.
        Throws:
        java.security.GeneralSecurityException - if certificate failed to load.
      • loadCertificate

        public static java.security.cert.X509Certificate loadCertificate​(java.lang.String file)
                                                                  throws java.io.IOException,
                                                                         java.security.GeneralSecurityException
        Loads an X.509 certificate from the specified file. The certificate file must be in PEM/Base64 format and start with "BEGIN CERTIFICATE" and end with "END CERTIFICATE" line.
        Parameters:
        file - the file to load the certificate from.
        Returns:
        java.security.cert.X509Certificate the loaded certificate.
        Throws:
        java.io.IOException - if I/O error occurs
        java.security.GeneralSecurityException - if security problems occurs.
      • loadCertificates

        public static java.security.cert.X509Certificate[] loadCertificates​(java.lang.String file)
                                                                     throws java.io.IOException,
                                                                            java.security.GeneralSecurityException
        Loads multiple X.509 certificates from the specified file. Each certificate must be in PEM/Base64 format and start with "BEGIN CERTIFICATE" and end with "END CERTIFICATE" line.
        Parameters:
        file - the certificate file to load the certificate from.
        Returns:
        an array of certificates loaded from the file.
        Throws:
        java.io.IOException - if I/O error occurs
        java.security.GeneralSecurityException - if security problems occurs.
      • readCertificate

        public static java.security.cert.X509Certificate readCertificate​(java.io.BufferedReader reader)
                                                                  throws java.io.IOException,
                                                                         java.security.GeneralSecurityException
        Loads a X.509 certificate from the specified reader. The certificate contents must start with "BEGIN CERTIFICATE" line and end with "END CERTIFICATE" line, and be in PEM/Base64 format.

        This function does not close the input stream.

        Parameters:
        reader - the stream from which load the certificate.
        Returns:
        the loaded certificate or null if there was no certificate in the stream or the stream is closed.
        Throws:
        java.io.IOException - if I/O error occurs
        java.security.GeneralSecurityException - if security problems occurs.
      • loadCrl

        public static java.security.cert.X509CRL loadCrl​(java.lang.String file)
                                                  throws java.io.IOException,
                                                         java.security.GeneralSecurityException
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
      • loadCrl

        public static java.security.cert.X509CRL loadCrl​(java.io.InputStream in)
                                                  throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • getTrustedCertificates

        public static java.util.Collection<java.security.cert.X509Certificate> getTrustedCertificates​(java.security.KeyStore keyStore,
                                                                                                      java.security.cert.X509CertSelector selector)
                                                                                               throws java.security.KeyStoreException
        Throws:
        java.security.KeyStoreException