Class KeyStoreWrapper


  • public class KeyStoreWrapper
    extends Object
    author Pascal Knueppel
    created at: 09.12.2019 - 08:20

    this class will be used to have the usage of a keystore wrapped in a single place. Means we will hold the password of the keystore, the aliases and the key passwords within this wrapper
    • Constructor Detail

      • KeyStoreWrapper

        public KeyStoreWrapper​(KeyStore keyStore,
                               String privateKeyPassword)
        constructor to befill the entries for this class
        it is expected that the keystore-password has already been entered into the keystore object therefore we wont need it anymore for the keystore.
        Parameters:
        keyStore - the keystore that should be accessible
        privateKeyPassword - the password used to access the private keys (the keystore is expected to contain a single entry)
      • KeyStoreWrapper

        public KeyStoreWrapper​(byte[] keyStore,
                               String keystorePassword)
        constructor to befill the entries for this class
        it is expected that the keystore-password has already been entered into the keystore object therefore we wont need it anymore

        The keystore is expected to be of type JKS
        Parameters:
        keyStore - the keystore that should be accessible
        keystorePassword - the keystore to open the keystore
      • KeyStoreWrapper

        public KeyStoreWrapper​(byte[] keyStore,
                               KeyStoreSupporter.KeyStoreType keyStoreType,
                               String keystorePassword)
        constructor to befill the entries for this class
        it is expected that the keystore-password has already been entered into the keystore object therefore we wont need it anymore
        Parameters:
        keyStore - the keystore that should be accessible
        keyStoreType - the type of the keystore
        keystorePassword - the keystore to open the keystore
      • KeyStoreWrapper

        public KeyStoreWrapper​(InputStream keyStore,
                               String keystorePassword)
        constructor to befill the entries for this class
        it is expected that the keystore-password has already been entered into the keystore object therefore we wont need it anymore

        The keystore is expected to be of type JKS
        Parameters:
        keyStore - the keystore that should be accessible
        keystorePassword - the keystore to open the keystore
      • KeyStoreWrapper

        public KeyStoreWrapper​(InputStream keyStore,
                               KeyStoreSupporter.KeyStoreType keyStoreType,
                               String keystorePassword)
        constructor to befill the entries for this class
        it is expected that the keystore-password has already been entered into the keystore object therefore we wont need it anymore
        Parameters:
        keyStore - the keystore that should be accessible
        keyStoreType - the type of the keystore
        keystorePassword - the keystore to open the keystore
      • KeyStoreWrapper

        public KeyStoreWrapper​(KeyStore keyStore,
                               String keystorePassword,
                               KeyStoreWrapper.AliasPasswordPair aliasPasswordPair,
                               KeyStoreWrapper.AliasPasswordPair... aliasPasswordPairs)
        constructor to befill the entries for this class
        it is expected that the keystore-password has already been entered into the keystore object therefore we wont need it anymore
        Parameters:
        keyStore - the keystore that should be accessible
        keystorePassword - the keystore to open the keystore
        aliasPasswordPair - a single alias key-password pair to access at least a single entry within the keystore
        aliasPasswordPairs - a list of alias key-password pairs to access other entreies as well
      • KeyStoreWrapper

        public KeyStoreWrapper​(byte[] keyStore,
                               KeyStoreSupporter.KeyStoreType keyStoreType,
                               String keystorePassword,
                               KeyStoreWrapper.AliasPasswordPair aliasPasswordPair,
                               KeyStoreWrapper.AliasPasswordPair... aliasPasswordPairs)
        constructor to befill the entries for this class
        Parameters:
        keyStore - the keystore that should be accessible
        keyStoreType - to resolve the given keystore into its appropriate type
        keystorePassword - the password to access the keystore if necessary
        aliasPasswordPair - a single alias key-password pair to access at least a single entry within the keystore
        aliasPasswordPairs - a list of alias key-password pairs to access other entreies as well
      • KeyStoreWrapper

        public KeyStoreWrapper​(File keyStore,
                               String keystorePassword,
                               KeyStoreWrapper.AliasPasswordPair aliasPasswordPair,
                               KeyStoreWrapper.AliasPasswordPair... aliasPasswordPairs)
        constructor to befill the entries for this class
        Parameters:
        keyStore - the keystore that should be accessible. It is necessary for the keystore to have an appropriate file ending like 'jks', 'jceks', 'p12' or 'pfx'!
        keystorePassword - the password to access the keystore if necessary
        aliasPasswordPair - a single alias key-password pair to access at least a single entry within the keystore
        aliasPasswordPairs - a list of alias key-password pairs to access other entreies as well
    • Method Detail

      • getPrivateKey

        public Optional<PrivateKey> getPrivateKey​(String alias)
        will extract the private key for the given alias
        Parameters:
        alias - the keystore entry to get the private key from
        Returns:
        the private key of the alias
      • getPrivateKey

        public Optional<PrivateKey> getPrivateKey​(String alias,
                                                  String password)
        this method will extract a private key with the given alias and the given password
        Parameters:
        alias - the alias that holds the private key
        password - the password to access the private key
        Returns:
        the private key or null if no entry was found
      • getCertificate

        public Optional<X509Certificate> getCertificate​(String alias)
        will read the certificate from the given alias
        Parameters:
        alias - the keystore entry to read
        Returns:
        the certificate under the given keystore entry
      • getAliasesAsList

        public List<String> getAliasesAsList()
        will return all aliases as list.
        this is just a convenience method to prevent handling with KeyStoreException
      • getKeyStore

        public KeyStore getKeyStore()
        the keystore that is the main object of this class
      • getKeystorePassword

        public String getKeystorePassword()
        the password to access the keystore
      • setKeyStore

        public void setKeyStore​(KeyStore keyStore)
        the keystore that is the main object of this class
      • setKeystorePassword

        public void setKeystorePassword​(String keystorePassword)
        the password to access the keystore
      • canEqual

        protected boolean canEqual​(Object other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object