Class KeyStoreFactory
java.lang.Object
se.swedenconnect.security.credential.factory.KeyStoreFactory
Factory class for loading and unlocking a
KeyStore
.- Author:
- Martin Lindström
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Symbolic constant for the PKCS11 KeyStore type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyStore
loadKeyStore
(InputStream stream, char[] password, String type, String provider) Loads and unlocks aKeyStore
.static KeyStore
loadKeyStore
(StoreConfiguration storeConfiguration, ConfigurationResourceLoader resourceLoader) Given aStoreConfiguration
object, this method loads and unlocks aKeyStore
.static KeyStore
loadPkcs11KeyStore
(Pkcs11Configuration pkcs11Configuration, char[] pin) Loads and unlocks a PKCS#11 key store.
-
Field Details
-
PKCS11_KEYSTORE_TYPE
Symbolic constant for the PKCS11 KeyStore type.- See Also:
-
-
Constructor Details
-
KeyStoreFactory
public KeyStoreFactory()
-
-
Method Details
-
loadKeyStore
@Nonnull public static KeyStore loadKeyStore(@Nullable InputStream stream, @Nullable char[] password, @Nullable String type, @Nullable String provider) throws KeyStoreException, NoSuchProviderException Loads and unlocks aKeyStore
.To create a
KeyStore
for a PKCS#11 device, useloadPkcs11KeyStore(Pkcs11Configuration, char[])
.- Parameters:
stream
- anInputStream
pointing at the key store (ifnull
an emptyKeyStore
will be created)password
- the password for unlocking the key store (may benull
)type
- the key store type, if not supplied,KeyStore.getDefaultType()
will be assumedprovider
- the security provider to use (if not provided, the default provider will be used)- Returns:
- a loaded and unlocked
KeyStore
- Throws:
KeyStoreException
- for errors during loading and unlocking of the key storeNoSuchProviderException
- if the given provider does not exist
-
loadPkcs11KeyStore
@Nonnull public static KeyStore loadPkcs11KeyStore(@Nonnull Pkcs11Configuration pkcs11Configuration, @Nonnull char[] pin) throws KeyStoreException Loads and unlocks a PKCS#11 key store.- Parameters:
pkcs11Configuration
- the PKCS#11 configurationpin
- the PIN to unlock the key store- Returns:
- a loaded and unlocked
KeyStore
- Throws:
KeyStoreException
- for errors during loading and unlocking of the key store
-
loadKeyStore
@Nonnull public static KeyStore loadKeyStore(@Nonnull StoreConfiguration storeConfiguration, @Nullable ConfigurationResourceLoader resourceLoader) throws IllegalArgumentException, KeyStoreException, NoSuchProviderException, IOException, Pkcs11ConfigurationException Given aStoreConfiguration
object, this method loads and unlocks aKeyStore
.- Parameters:
storeConfiguration
- the configuration objectresourceLoader
- for reading configuration resources intoInputStream
s, ifnull
, aDefaultConfigurationResourceLoader
will be used- Returns:
- a
KeyStore
- Throws:
IllegalArgumentException
- for missing or illegal input valuesKeyStoreException
- for problems unlocking the key storeNoSuchProviderException
- if a reference security provider does not existIOException
- for errors reading files referenced in the configurationPkcs11ConfigurationException
- for invalid PKCS#11 configuration
-