Class CertUtil

java.lang.Object
org.forgerock.openidm.util.CertUtil

public class CertUtil extends Object
Utilities for generating, serializing, and deserializing Certificates.
  • Method Details

    • generateCertificate

      public static org.apache.commons.lang3.tuple.Pair<X509Certificate,PrivateKey> generateCertificate(String commonName, String algorithm, int keySize, String signatureAlgorithm, String validFrom, String validTo) throws Exception
      Generates a self signed certificate using the given properties.
      Parameters:
      commonName - the common name to use for the new certificate
      algorithm - the algorithm to use
      keySize - the keysize to use
      signatureAlgorithm - the signature algorithm to use
      validFrom - when the certificate is valid from
      validTo - when the certificate is valid until
      Returns:
      The generated certificate
      Throws:
      Exception
    • generateCertificate

      public static org.apache.commons.lang3.tuple.Pair<X509Certificate,PrivateKey> generateCertificate(String commonName, String organization, String organizationUnit, String stateOrProvince, String country, String locality, String algorithm, int keySize, String signatureAlgorithm, String validFrom, String validTo) throws Exception
      Generates a self signed certificate using the given properties.
      Parameters:
      commonName - the subject's common name
      organization - the subject's organization name
      organizationUnit - the subject's organization unit name
      stateOrProvince - the subject's state or province
      country - the subject's country code
      locality - the subject's locality
      algorithm - the algorithm to use
      keySize - the keysize to use
      signatureAlgorithm - the signature algorithm to use
      validFrom - when the certificate is valid from
      validTo - when the certificate is valid until
      Returns:
      The generated certificate
      Throws:
      Exception
    • getCertString

      public static String getCertString(Object object) throws Exception
      Returns a PEM formatted string representation of an object
      Parameters:
      object - the object to write
      Returns:
      a PEM formatted string representation of the object
      Throws:
      Exception
    • fromPem

      public static <T> T fromPem(String pem) throws Exception
      Returns an object from a PEM String representation
      Parameters:
      pem - the PEM String representation
      Returns:
      the object
      Throws:
      Exception
    • readCertificate

      public static Certificate readCertificate(String certString) throws Exception
      Reads a certificate from a supplied string representation, and a supplied type.
      Parameters:
      certString - A String representation of a certificate
      Returns:
      The certificate
      Throws:
      Exception
    • readCertificateChain

      public static Certificate[] readCertificateChain(List<String> certStringChain) throws Exception
      Reads a certificate chain from a supplied string array representation, and a supplied type.
      Parameters:
      certStringChain - an array of strings representing a certificate chain
      Returns:
      the certificate chain
      Throws:
      Exception