Class KeyStoreUtil


  • public class KeyStoreUtil
    extends java.lang.Object
    Utility for loading, saving, and manipulating KeyStores.
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyStoreUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.security.KeyStore createEmptyKeyStore​(java.lang.String keyStoreType, java.lang.String provider)
      Creates and initializes an empty KeyStore using the specified keyStoreType.
      static java.security.KeyStore createRootCertificateKeyStore​(java.lang.String keyStoreType, java.security.cert.X509Certificate certificate, java.lang.String privateKeyAlias, java.security.PrivateKey privateKey, java.lang.String privateKeyPassword, java.lang.String provider)
      Creates a new KeyStore containing the specified root certificate and private key.
      static javax.net.ssl.KeyManager[] getKeyManagers​(java.security.KeyStore keyStore, java.lang.String keyStorePassword, java.lang.String keyManagerAlgorithm, java.lang.String provider)
      Retrieve the KeyManagers for the specified KeyStore.
      • Methods inherited from class java.lang.Object

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

      • KeyStoreUtil

        public KeyStoreUtil()
    • Method Detail

      • createEmptyKeyStore

        public static java.security.KeyStore createEmptyKeyStore​(java.lang.String keyStoreType,
                                                                 java.lang.String provider)
        Creates and initializes an empty KeyStore using the specified keyStoreType.
        Parameters:
        keyStoreType - type of key store to initialize, or null to use the system default
        provider - JCA provider to use, or null to use the system default
        Returns:
        a new KeyStore
      • createRootCertificateKeyStore

        public static java.security.KeyStore createRootCertificateKeyStore​(java.lang.String keyStoreType,
                                                                           java.security.cert.X509Certificate certificate,
                                                                           java.lang.String privateKeyAlias,
                                                                           java.security.PrivateKey privateKey,
                                                                           java.lang.String privateKeyPassword,
                                                                           java.lang.String provider)
        Creates a new KeyStore containing the specified root certificate and private key.
        Parameters:
        keyStoreType - type of the generated KeyStore, such as PKCS12 or JKS
        certificate - root certificate to add to the KeyStore
        privateKeyAlias - alias for the private key in the KeyStore
        privateKey - private key to add to the KeyStore
        privateKeyPassword - password for the private key
        provider - JCA provider to use, or null to use the system default
        Returns:
        new KeyStore containing the root certificate and private key
      • getKeyManagers

        public static javax.net.ssl.KeyManager[] getKeyManagers​(java.security.KeyStore keyStore,
                                                                java.lang.String keyStorePassword,
                                                                java.lang.String keyManagerAlgorithm,
                                                                java.lang.String provider)
        Retrieve the KeyManagers for the specified KeyStore.
        Parameters:
        keyStore - the KeyStore to retrieve KeyManagers from
        keyStorePassword - the KeyStore password
        keyManagerAlgorithm - key manager algorithm to use, or null to use the system default
        provider - JCA provider to use, or null to use the system default
        Returns:
        KeyManagers for the specified KeyStore