Class KeyStoreManagementService


  • @Named
    @Singleton
    public class KeyStoreManagementService
    extends java.lang.Object
    Service for managing keystores (list, change alias, change passwords, import keystore). Follows Single Responsibility Principle (SOLID-S).
    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.slf4j.Logger log  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void changeAlias​(java.io.File keystoreFile, java.lang.String keystoreType, char[] storePassword, java.lang.String alias, java.lang.String destAlias, char[] keyPassword)
      Change alias name.
      void changeKeyPassword​(java.io.File keystoreFile, java.lang.String keystoreType, char[] storePassword, java.lang.String alias, char[] oldKeyPassword, char[] newKeyPassword)
      Change key password.
      void changeStorePassword​(java.io.File keystoreFile, java.lang.String keystoreType, char[] oldPassword, char[] newPassword)
      Change store password.
      private void importAllEntries​(java.security.KeyStore sourceKs, java.security.KeyStore destKs, char[] sourceKeyPassword, char[] destKeyPassword)  
      void importKeystore​(java.io.File sourceKeystoreFile, java.lang.String sourceType, char[] sourcePassword, java.io.File destKeystoreFile, java.lang.String destType, char[] destPassword, java.lang.String sourceAlias, java.lang.String destAlias, char[] sourceKeyPassword, char[] destKeyPassword)
      Import keystore.
      private void importSingleEntry​(java.security.KeyStore sourceKs, java.security.KeyStore destKs, java.lang.String sourceAlias, java.lang.String destAlias, char[] sourceKeyPassword, char[] destKeyPassword)  
      void listAliases​(java.io.File keystoreFile, java.lang.String keystoreType, char[] password, java.lang.String specificAlias)
      List all aliases in a keystore.
      private void listAllAliases​(java.security.KeyStore keystore)  
      private void listSingleAlias​(java.security.KeyStore keystore, java.lang.String alias)  
      private java.security.KeyStore loadKeyStore​(java.io.File keystoreFile, java.lang.String keystoreType, char[] password)  
      private java.security.KeyStore loadOrCreateKeyStore​(java.io.File keystoreFile, java.lang.String keystoreType, char[] password)  
      private void saveKeyStore​(java.security.KeyStore keystore, java.io.File keystoreFile, char[] password)  
      • Methods inherited from class java.lang.Object

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

      • log

        private static final org.slf4j.Logger log
    • Constructor Detail

      • KeyStoreManagementService

        public KeyStoreManagementService()
    • Method Detail

      • listAliases

        public void listAliases​(java.io.File keystoreFile,
                                java.lang.String keystoreType,
                                char[] password,
                                java.lang.String specificAlias)
                         throws java.lang.Exception
        List all aliases in a keystore.
        Throws:
        java.lang.Exception
      • changeAlias

        public void changeAlias​(java.io.File keystoreFile,
                                java.lang.String keystoreType,
                                char[] storePassword,
                                java.lang.String alias,
                                java.lang.String destAlias,
                                char[] keyPassword)
                         throws java.lang.Exception
        Change alias name.
        Throws:
        java.lang.Exception
      • changeKeyPassword

        public void changeKeyPassword​(java.io.File keystoreFile,
                                      java.lang.String keystoreType,
                                      char[] storePassword,
                                      java.lang.String alias,
                                      char[] oldKeyPassword,
                                      char[] newKeyPassword)
                               throws java.lang.Exception
        Change key password.
        Throws:
        java.lang.Exception
      • changeStorePassword

        public void changeStorePassword​(java.io.File keystoreFile,
                                        java.lang.String keystoreType,
                                        char[] oldPassword,
                                        char[] newPassword)
                                 throws java.lang.Exception
        Change store password.
        Throws:
        java.lang.Exception
      • importKeystore

        public void importKeystore​(java.io.File sourceKeystoreFile,
                                   java.lang.String sourceType,
                                   char[] sourcePassword,
                                   java.io.File destKeystoreFile,
                                   java.lang.String destType,
                                   char[] destPassword,
                                   java.lang.String sourceAlias,
                                   java.lang.String destAlias,
                                   char[] sourceKeyPassword,
                                   char[] destKeyPassword)
                            throws java.lang.Exception
        Import keystore.
        Throws:
        java.lang.Exception
      • listSingleAlias

        private void listSingleAlias​(java.security.KeyStore keystore,
                                     java.lang.String alias)
                              throws java.security.KeyStoreException
        Throws:
        java.security.KeyStoreException
      • listAllAliases

        private void listAllAliases​(java.security.KeyStore keystore)
                             throws java.security.KeyStoreException
        Throws:
        java.security.KeyStoreException
      • importSingleEntry

        private void importSingleEntry​(java.security.KeyStore sourceKs,
                                       java.security.KeyStore destKs,
                                       java.lang.String sourceAlias,
                                       java.lang.String destAlias,
                                       char[] sourceKeyPassword,
                                       char[] destKeyPassword)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • importAllEntries

        private void importAllEntries​(java.security.KeyStore sourceKs,
                                      java.security.KeyStore destKs,
                                      char[] sourceKeyPassword,
                                      char[] destKeyPassword)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadKeyStore

        private java.security.KeyStore loadKeyStore​(java.io.File keystoreFile,
                                                    java.lang.String keystoreType,
                                                    char[] password)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadOrCreateKeyStore

        private java.security.KeyStore loadOrCreateKeyStore​(java.io.File keystoreFile,
                                                            java.lang.String keystoreType,
                                                            char[] password)
                                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • saveKeyStore

        private void saveKeyStore​(java.security.KeyStore keystore,
                                  java.io.File keystoreFile,
                                  char[] password)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception