Class KeyStoreWrapper
- java.lang.Object
-
- de.captaingoldfish.scim.sdk.client.keys.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKeyStoreWrapper.AliasPasswordPairused as data holder to hold the key-passwords for any alias
-
Constructor Summary
Constructors Constructor Description 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 anymoreKeyStoreWrapper(byte[] keyStore, KeyStoreSupporter.KeyStoreType keyStoreType, String keystorePassword, KeyStoreWrapper.AliasPasswordPair aliasPasswordPair, KeyStoreWrapper.AliasPasswordPair... aliasPasswordPairs)constructor to befill the entries for this classKeyStoreWrapper(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 JKSKeyStoreWrapper(File keyStore, String keystorePassword, KeyStoreWrapper.AliasPasswordPair aliasPasswordPair, KeyStoreWrapper.AliasPasswordPair... aliasPasswordPairs)constructor to befill the entries for this classKeyStoreWrapper(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 anymoreKeyStoreWrapper(InputStream keyStore, KeyStoreSupporter.KeyStoreType keyStoreType, String keystorePassword, KeyStoreWrapper.AliasPasswordPair aliasPasswordPair, KeyStoreWrapper.AliasPasswordPair... aliasPasswordPairs)constructor to befill the entries for this classKeyStoreWrapper(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 JKSKeyStoreWrapper(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.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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Enumeration<String>getAliases()will return all aliases without having to handle the exception.List<String>getAliasesAsList()will return all aliases as list.Optional<X509Certificate>getCertificate(String alias)will read the certificate from the given aliasOptional<X509Certificate[]>getCertificateChain(String alias)will read the certificate from the given aliasOptional<PrivateKey>getPrivateKey(String alias)will extract the private key for the given aliasOptional<PrivateKey>getPrivateKey(String alias, String password)this method will extract a private key with the given alias and the given password
-
-
-
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 accessibleprivateKeyPassword- 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 accessiblekeystorePassword- 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 accessiblekeyStoreType- the type of the keystorekeystorePassword- 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 accessiblekeystorePassword- 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 accessiblekeyStoreType- the type of the keystorekeystorePassword- 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 accessiblekeystorePassword- the keystore to open the keystorealiasPasswordPair- a single alias key-password pair to access at least a single entry within the keystorealiasPasswordPairs- 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 accessiblekeyStoreType- to resolve the given keystore into its appropriate typekeystorePassword- the password to access the keystore if necessaryaliasPasswordPair- a single alias key-password pair to access at least a single entry within the keystorealiasPasswordPairs- a list of alias key-password pairs to access other entreies as well
-
KeyStoreWrapper
public KeyStoreWrapper(InputStream 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 accessiblekeyStoreType- to resolve the given keystore into its appropriate typekeystorePassword- the password to access the keystore if necessaryaliasPasswordPair- a single alias key-password pair to access at least a single entry within the keystorealiasPasswordPairs- 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 necessaryaliasPasswordPair- a single alias key-password pair to access at least a single entry within the keystorealiasPasswordPairs- 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 keypassword- 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
-
getCertificateChain
public Optional<X509Certificate[]> getCertificateChain(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 withKeyStoreException
-
getAliases
public Enumeration<String> getAliases()
will return all aliases without having to handle the exception.
this is just a convenience method to prevent handling withKeyStoreException
-
-