Class CertUtils


  • public class CertUtils
    extends java.lang.Object
    A collection of utility methods related to cert creation and conversion
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[][] buildDERCertChain​(java.security.cert.Certificate[] certChain)
      Converts a java Certificate Chain to a der encoded byte array.
      static int computeJavaPrivateKeySize​(java.security.PrivateKey privateKey)
      Computes the size of a JCE PrivateKey
      static java.security.PrivateKey createJCEPrivateKey​(byte[] encodedPriKey, java.lang.String keyWrappingFormat)
      Create a JCE PrivateKey given a DER encoded set of bytes representing the key.
      static PrivateKeyHolder createJCEPrivateKeyHolder​(byte[] encodedPriKey, java.lang.String keyWrappingFormat)
      Create a JCE PrivateKey given a DER encoded set of bytes representing the key.
      static java.lang.String getCommonSubjectName​(java.security.cert.X509Certificate x509Certificate)
      Returns value of "CN" attribute from subject name of this certificate.
      static java.security.cert.Certificate importCertificate​(byte[] certData)
      Creates a JCE X509 certificate from a DER encoded byte array representing the certificate.
      static java.security.cert.Certificate[] importCertificateChain​(byte[][] certData)
      Creates a JCE X509 certificate chain from a DER encoded byte array representing the cert chain
      • Methods inherited from class java.lang.Object

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

      • importCertificate

        public static java.security.cert.Certificate importCertificate​(byte[] certData)
                                                                throws java.security.cert.CertificateException,
                                                                       java.io.IOException
        Creates a JCE X509 certificate from a DER encoded byte array representing the certificate.
        Parameters:
        certData -
        Returns:
        java.security.cert.Certificate
        Throws:
        java.security.cert.CertificateException
        java.io.IOException
      • importCertificateChain

        public static java.security.cert.Certificate[] importCertificateChain​(byte[][] certData)
                                                                       throws java.security.cert.CertificateException,
                                                                              java.io.IOException
        Creates a JCE X509 certificate chain from a DER encoded byte array representing the cert chain
        Parameters:
        certData -
        Returns:
        certificate chain
        Throws:
        java.security.cert.CertificateException
        java.io.IOException
      • createJCEPrivateKey

        public static java.security.PrivateKey createJCEPrivateKey​(byte[] encodedPriKey,
                                                                   java.lang.String keyWrappingFormat)
                                                            throws java.security.NoSuchAlgorithmException,
                                                                   java.security.spec.InvalidKeySpecException
        Create a JCE PrivateKey given a DER encoded set of bytes representing the key.
        Parameters:
        encodedPriKey -
        keyWrappingFormat -
        Returns:
        PrivateKey
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • createJCEPrivateKeyHolder

        public static PrivateKeyHolder createJCEPrivateKeyHolder​(byte[] encodedPriKey,
                                                                 java.lang.String keyWrappingFormat)
                                                          throws java.security.NoSuchAlgorithmException,
                                                                 java.security.spec.InvalidKeySpecException
        Create a JCE PrivateKey given a DER encoded set of bytes representing the key.
        Parameters:
        encodedPriKey -
        keyWrappingFormat -
        Returns:
        JCEPrivateKeyHolder
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • buildDERCertChain

        public static byte[][] buildDERCertChain​(java.security.cert.Certificate[] certChain)
                                          throws java.security.cert.CertificateEncodingException,
                                                 java.security.cert.CertificateException
        Converts a java Certificate Chain to a der encoded byte array.
        Parameters:
        certChain -
        Returns:
        byte[][] representing the der cert chain
        Throws:
        java.security.cert.CertificateEncodingException
        java.security.cert.CertificateException
      • computeJavaPrivateKeySize

        public static int computeJavaPrivateKeySize​(java.security.PrivateKey privateKey)
                                             throws java.security.NoSuchAlgorithmException,
                                                    java.security.spec.InvalidKeySpecException
        Computes the size of a JCE PrivateKey
        Parameters:
        privateKey -
        Returns:
        size of the JCE PrivateKey
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • getCommonSubjectName

        public static java.lang.String getCommonSubjectName​(java.security.cert.X509Certificate x509Certificate)
        Returns value of "CN" attribute from subject name of this certificate.
        Parameters:
        x509Certificate -
        Returns:
        String