Class KeyStoreUtils


  • public final class KeyStoreUtils
    extends java.lang.Object
    Provides utility methods for using a KeyStore.
    Author:
    Middleware Services
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.security.KeyStore.Entry getEntry​(java.lang.String alias, java.security.KeyStore keystore, char[] password)
      Returns a keystore entry from the supplied keystore.
      static java.security.KeyStore newInstance()
      Creates a new KeyStore with the default keystore type and initializes it.
      static java.security.KeyStore newInstance​(char[] password)
      Creates a new KeyStore with the default keystore type and initializes it.
      static java.security.KeyStore newInstance​(java.lang.String type)
      Creates a new KeyStore and initializes it.
      static java.security.KeyStore newInstance​(java.lang.String type, char[] password)
      Creates a new KeyStore and initializes it.
      static void setCertificateEntry​(java.lang.String alias, java.security.KeyStore keystore, java.security.cert.Certificate... certs)
      Sets certificate entries on the supplied keystore.
      static void setEntry​(java.lang.String alias, java.security.KeyStore.Entry entry, java.security.KeyStore keystore, char[] password)
      Sets a keystore entry on the supplied keystore.
      static void setKeyEntry​(java.lang.String alias, java.security.KeyStore keystore, char[] password, java.security.Key key, java.security.cert.Certificate... certs)
      Sets a key entry on the supplied keystore.
      • Methods inherited from class java.lang.Object

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

      • newInstance

        public static java.security.KeyStore newInstance()
                                                  throws java.security.GeneralSecurityException
        Creates a new KeyStore with the default keystore type and initializes it.
        Returns:
        initialized keystore
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be initialized
      • newInstance

        public static java.security.KeyStore newInstance​(char[] password)
                                                  throws java.security.GeneralSecurityException
        Creates a new KeyStore with the default keystore type and initializes it.
        Parameters:
        password - to protect the keystore
        Returns:
        initialized keystore
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be initialized
      • newInstance

        public static java.security.KeyStore newInstance​(java.lang.String type)
                                                  throws java.security.GeneralSecurityException
        Creates a new KeyStore and initializes it.
        Parameters:
        type - of keystore instance
        Returns:
        initialized keystore
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be initialized
      • newInstance

        public static java.security.KeyStore newInstance​(java.lang.String type,
                                                         char[] password)
                                                  throws java.security.GeneralSecurityException
        Creates a new KeyStore and initializes it.
        Parameters:
        type - of keystore instance
        password - to protect the keystore
        Returns:
        initialized keystore
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be initialized
      • getEntry

        public static java.security.KeyStore.Entry getEntry​(java.lang.String alias,
                                                            java.security.KeyStore keystore,
                                                            char[] password)
                                                     throws java.security.GeneralSecurityException
        Returns a keystore entry from the supplied keystore.
        Parameters:
        alias - of the entry to return
        keystore - to read the entry from
        password - to access the keystore
        Returns:
        keystore entry
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be read
        java.lang.IllegalArgumentException - if the alias does not exist
      • setEntry

        public static void setEntry​(java.lang.String alias,
                                    java.security.KeyStore.Entry entry,
                                    java.security.KeyStore keystore,
                                    char[] password)
                             throws java.security.GeneralSecurityException
        Sets a keystore entry on the supplied keystore.
        Parameters:
        alias - of the supplied entry
        entry - to set
        keystore - to set the entry on
        password - to protect the entry
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be modified
      • setKeyEntry

        public static void setKeyEntry​(java.lang.String alias,
                                       java.security.KeyStore keystore,
                                       char[] password,
                                       java.security.Key key,
                                       java.security.cert.Certificate... certs)
                                throws java.security.GeneralSecurityException
        Sets a key entry on the supplied keystore.
        Parameters:
        alias - of the supplied key
        keystore - to set the key on
        password - to protect the key
        key - to set
        certs - associated with the key
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be modified
      • setCertificateEntry

        public static void setCertificateEntry​(java.lang.String alias,
                                               java.security.KeyStore keystore,
                                               java.security.cert.Certificate... certs)
                                        throws java.security.GeneralSecurityException
        Sets certificate entries on the supplied keystore. For certificate arrays of size greater than 1, the alias is appended with an index.
        Parameters:
        alias - of the supplied certificate(s)
        keystore - to set the cert(s) on
        certs - to set
        Throws:
        java.security.GeneralSecurityException - if the keystore cannot be modified