Package no.digipost.security.keystore
Class KeyStoreBuilder
java.lang.Object
no.digipost.security.keystore.KeyStoreBuilder
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Function<? super X509Certificate,
String> The default way to create aliases for certificates, which uses certificates' Subject DNs,serial numbers
, and Issuer DNs to create aliases. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncontaining
(X509Certificate certificate) Add a certificate which should be contained in the resultingKeyStore
.containing
(X509Certificate certificate, String alias) Add a certificate which should be contained in the resultingKeyStore
with the given alias.containing
(Collection<X509Certificate> certificates) Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR
.containing
(Stream<X509Certificate> certificates) Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR
.containing
(Stream<X509Certificate> certificates, Function<? super X509Certificate, String> aliasCreator) Add certificates which should be contained in the resulting key store.loadFrom
(InputStream keyStoreStream) Load key store fromInputStream
into a newKeyStore
.loadFromClasspath
(String classpathResourceName) Load key store from classpath resource into a newKeyStore
.Build a new key store with no password to access its content.withPassword
(char[] password) Build a new key store with the given password to access its content.withPassword
(String password) Build a new key store with the given password to access its content.
-
Field Details
-
DEFAULT_ALIAS_CREATOR
The default way to create aliases for certificates, which uses certificates' Subject DNs,serial numbers
, and Issuer DNs to create aliases. This alias creator is to ensure unique aliases for added certificates, and should not be used for adding certificates which one wishes to retrieve by alias from the resulting key store.
-
-
Constructor Details
-
KeyStoreBuilder
-
-
Method Details
-
containing
Add a certificate which should be contained in the resultingKeyStore
. Its alias will be created byDEFAULT_ALIAS_CREATOR
.- Parameters:
certificate
- the certificate to add to the resulting key store.- Returns:
- the builder
-
containing
Add a certificate which should be contained in the resultingKeyStore
with the given alias.- Parameters:
certificate
- the certificate to add to the resulting key store.alias
- the alias which the certificate may be retrieved from the resulting key store.- Returns:
- the builder
-
containing
Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR
.- Parameters:
certificates
- the certificates to add to the newKeyStore
.- Returns:
- the builder.
-
containing
Add certificates which should be contained in the resulting key store, and which will be aliased usingDEFAULT_ALIAS_CREATOR
.- Parameters:
certificates
- the certificates to add to the newKeyStore
.- Returns:
- the builder.
-
containing
public KeyStoreBuilder containing(Stream<X509Certificate> certificates, Function<? super X509Certificate, String> aliasCreator) Add certificates which should be contained in the resulting key store.- Parameters:
certificates
- the certificates to add to the newKeyStore
.aliasCreator
- creates an alias for each certificate in the new key store.- Returns:
- the builder.
- Throws:
DuplicateAlias
- if the same alias is created for several certificates.
-
loadFromClasspath
Load key store from classpath resource into a newKeyStore
.- Parameters:
classpathResourceName
- the name of the classpath resource containing the key store. The resource is resolved from the root of the classpath.
-
loadFrom
Load key store fromInputStream
into a newKeyStore
.- Parameters:
keyStoreStream
- theInputStream
containing the key store.
-
withNoPassword
Build a new key store with no password to access its content.- Returns:
- the new
KeyStore
.
-
withPassword
Build a new key store with the given password to access its content.- Parameters:
password
- the password for the key store.- Returns:
- the new
KeyStore
.
-
withPassword
Build a new key store with the given password to access its content.- Parameters:
password
- the password for the key store.- Returns:
- the new
KeyStore
.
-