Class PemUtils

java.lang.Object
nl.altindag.ssl.pem.util.PemUtils

public final class PemUtils extends Object
Reads PEM formatted private keys and certificates as identity material and trust material and maps it to either a X509ExtendedKeyManager or X509ExtendedTrustManager.

The PemUtils provides also other methods for example to:
 - load trusted certificates and map it into a list of X509Certificate
 - load identity material and map it into a PrivateKey
 

The PemUtils serves mainly as a helper class to easily supply the PEM formatted SSL material for the SSLFactory, but can also be used for other purposes.

Author:
Hakan Altindag
  • Method Details

    • loadTrustMaterial

      public static X509ExtendedTrustManager loadTrustMaterial(String... certificatePaths)
      Loads certificates from the classpath and maps it to an instance of X509ExtendedTrustManager
    • loadTrustMaterial

      public static X509ExtendedTrustManager loadTrustMaterial(Path... certificatePaths)
      Loads certificates from the filesystem and maps it to an instance of X509ExtendedTrustManager
    • loadTrustMaterial

      public static X509ExtendedTrustManager loadTrustMaterial(InputStream... certificateStreams)
      Loads certificates from multiple InputStreams and maps it to an instance of X509ExtendedTrustManager
    • loadCertificate

      public static List<X509Certificate> loadCertificate(String... certificatePaths)
      Loads certificates from the classpath and maps it to a list of X509Certificate
    • loadCertificate

      public static List<X509Certificate> loadCertificate(Path... certificatePaths)
      Loads certificates from the filesystem and maps it to a list of X509Certificate
    • loadCertificate

      public static List<X509Certificate> loadCertificate(InputStream... certificateStreams)
      Loads certificates from multiple InputStreams and maps it to a list of X509Certificate
    • parseCertificate

      public static List<X509Certificate> parseCertificate(String certContent)
    • parseTrustMaterial

      public static X509ExtendedTrustManager parseTrustMaterial(String... certificateContents)
      Parses one or more certificates as a string representation and maps it to an instance of X509ExtendedTrustManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(String certificateChainPath, String privateKeyPath)
      Loads the identity material based on a certificate chain and a private key from the classpath and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(String certificateChainPath, String privateKeyPath, char[] keyPassword)
      Loads the identity material based on a certificate chain and a private key from the classpath and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(InputStream certificateChainStream, InputStream privateKeyStream)
      Loads the identity material based on a certificate chain and a private key as an InputStream and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(InputStream certificateChainStream, InputStream privateKeyStream, char[] keyPassword)
      Loads the identity material based on a certificate chain and a private key as an InputStream and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(Path certificateChainPath, Path privateKeyPath)
      Loads the identity material based on a certificate chain and a private key from the filesystem and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(Path certificateChainPath, Path privateKeyPath, char[] keyPassword)
      Loads the identity material based on a certificate chain and a private key from the filesystem and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(String identityPath)
      Loads the identity material based on a combined file containing the certificate chain and the private key from the classpath and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(String identityPath, char[] keyPassword)
      Loads the identity material based on a combined file containing the certificate chain and the private key from the classpath and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(Path identityPath)
      Loads the identity material based on a combined file containing the certificate chain and the private key from the filesystem and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(Path identityPath, char[] keyPassword)
      Loads the identity material based on a combined file containing the certificate chain and the private key from the filesystem and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(InputStream identityStream)
      Loads the identity material based on a combined entity containing the certificate chain and the private key from an InputStream and maps it to an instance of X509ExtendedKeyManager
    • loadIdentityMaterial

      public static X509ExtendedKeyManager loadIdentityMaterial(InputStream identityStream, char[] keyPassword)
      Loads the identity material based on a combined entity containing the certificate chain and the private key from an InputStream and maps it to an instance of X509ExtendedKeyManager
    • parseIdentityMaterial

      public static X509ExtendedKeyManager parseIdentityMaterial(String identityContent)
      Parses the identity material based on a string representation containing the certificate chain and the private key and maps it to an instance of X509ExtendedTrustManager
    • parseIdentityMaterial

      public static X509ExtendedKeyManager parseIdentityMaterial(String identityContent, char[] keyPassword)
      Parses the identity material based on a string representation containing the certificate chain and the private key and maps it to an instance of X509ExtendedTrustManager
    • parseIdentityMaterial

      public static X509ExtendedKeyManager parseIdentityMaterial(String certificateChainContent, String privateKeyContent, char[] keyPassword)
      Parses the identity material based on a string representation of the certificate chain and the private key and maps it to an instance of X509ExtendedTrustManager
    • loadPrivateKey

      public static PrivateKey loadPrivateKey(String identityPath)
      Loads the private key from the classpath and maps it to an instance of PrivateKey
    • loadPrivateKey

      public static PrivateKey loadPrivateKey(String identityPath, char[] keyPassword)
      Loads the private key from the classpath and maps it to an instance of PrivateKey
    • loadPrivateKey

      public static PrivateKey loadPrivateKey(Path identityPath)
      Loads the private key from the filesystem and maps it to an instance of PrivateKey
    • loadPrivateKey

      public static PrivateKey loadPrivateKey(Path identityPath, char[] keyPassword)
      Loads the private key from the filesystem and maps it to an instance of PrivateKey
    • loadPrivateKey

      public static PrivateKey loadPrivateKey(InputStream identityStream)
      Loads the private key from an InputStream and maps it to an instance of PrivateKey
    • loadPrivateKey

      public static PrivateKey loadPrivateKey(InputStream identityStream, char[] keyPassword)
      Loads the private key from an InputStream and maps it to an instance of PrivateKey
    • parsePrivateKey

      public static PrivateKey parsePrivateKey(String identityContent)
      Parses the private key based on a string representation of the private key and maps it to an instance of PrivateKey
    • parsePrivateKey

      public static PrivateKey parsePrivateKey(String identityContent, char[] keyPassword)
      Parses the private key based on a string representation of the private key and maps it to an instance of PrivateKey. If the identity content contains multiple private keys it will use only the first one.
    • extractPublicKey

      public static PublicKey extractPublicKey(PrivateKey privateKey)