Package org.ldaptive.ssl
Class KeyStoreUtils
java.lang.Object
org.ldaptive.ssl.KeyStoreUtils
Provides utility methods for using a
KeyStore.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyStore.EntryReturns a keystore entry from the supplied keystore.static KeyStoreCreates a newKeyStorewith the default keystore type and initializes it.static KeyStorenewInstance(char[] password) Creates a newKeyStorewith the default keystore type and initializes it.static KeyStorenewInstance(String type) Creates a newKeyStoreand initializes it.static KeyStorenewInstance(String type, char[] password) Creates a newKeyStoreand initializes it.static voidsetCertificateEntry(String alias, KeyStore keystore, Certificate... certs) Sets certificate entries on the supplied keystore.static voidsetEntry(String alias, KeyStore.Entry entry, KeyStore keystore, char[] password) Sets a keystore entry on the supplied keystore.static voidsetKeyEntry(String alias, KeyStore keystore, char[] password, Key key, Certificate... certs) Sets a key entry on the supplied keystore.
-
Field Details
-
DEFAULT_TYPE
Default keystore type.
-
-
Constructor Details
-
KeyStoreUtils
private KeyStoreUtils()Default constructor.
-
-
Method Details
-
newInstance
Creates a newKeyStorewith the default keystore type and initializes it.- Returns:
- initialized keystore
- Throws:
GeneralSecurityException- if the keystore cannot be initialized
-
newInstance
Creates a newKeyStorewith the default keystore type and initializes it.- Parameters:
password- to protect the keystore- Returns:
- initialized keystore
- Throws:
GeneralSecurityException- if the keystore cannot be initialized
-
newInstance
Creates a newKeyStoreand initializes it.- Parameters:
type- of keystore instance- Returns:
- initialized keystore
- Throws:
GeneralSecurityException- if the keystore cannot be initialized
-
newInstance
Creates a newKeyStoreand initializes it.- Parameters:
type- of keystore instancepassword- to protect the keystore- Returns:
- initialized keystore
- Throws:
GeneralSecurityException- if the keystore cannot be initialized
-
getEntry
public static KeyStore.Entry getEntry(String alias, KeyStore keystore, char[] password) throws GeneralSecurityException Returns a keystore entry from the supplied keystore.- Parameters:
alias- of the entry to returnkeystore- to read the entry frompassword- to access the keystore- Returns:
- keystore entry
- Throws:
GeneralSecurityException- if the keystore cannot be readIllegalArgumentException- if the alias does not exist
-
setEntry
public static void setEntry(String alias, KeyStore.Entry entry, KeyStore keystore, char[] password) throws GeneralSecurityException Sets a keystore entry on the supplied keystore.- Parameters:
alias- of the supplied entryentry- to setkeystore- to set the entry onpassword- to protect the entry- Throws:
GeneralSecurityException- if the keystore cannot be modified
-
setKeyEntry
public static void setKeyEntry(String alias, KeyStore keystore, char[] password, Key key, Certificate... certs) throws GeneralSecurityException Sets a key entry on the supplied keystore.- Parameters:
alias- of the supplied keykeystore- to set the key onpassword- to protect the keykey- to setcerts- associated with the key- Throws:
GeneralSecurityException- if the keystore cannot be modified
-
setCertificateEntry
public static void setCertificateEntry(String alias, KeyStore keystore, Certificate... certs) throws 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) oncerts- to set- Throws:
GeneralSecurityException- if the keystore cannot be modified
-