Package org.ldaptive.ssl
Class KeyStoreUtils
- java.lang.Object
-
- org.ldaptive.ssl.KeyStoreUtils
-
-
Field Summary
Fields Modifier and Type Field Description private static String
DEFAULT_TYPE
Default keystore type.
-
Constructor Summary
Constructors Modifier Constructor Description private
KeyStoreUtils()
Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static KeyStore.Entry
getEntry(String alias, KeyStore keystore, char[] password)
Returns a keystore entry from the supplied keystore.static KeyStore
newInstance()
Creates a newKeyStore
with the default keystore type and initializes it.static KeyStore
newInstance(char[] password)
Creates a newKeyStore
with the default keystore type and initializes it.static KeyStore
newInstance(String type)
Creates a newKeyStore
and initializes it.static KeyStore
newInstance(String type, char[] password)
Creates a newKeyStore
and initializes it.static void
setCertificateEntry(String alias, KeyStore keystore, Certificate... certs)
Sets certificate entries on the supplied keystore.static void
setEntry(String alias, KeyStore.Entry entry, KeyStore keystore, char[] password)
Sets a keystore entry on the supplied keystore.static void
setKeyEntry(String alias, KeyStore keystore, char[] password, Key key, Certificate... certs)
Sets a key entry on the supplied keystore.
-
-
-
Field Detail
-
DEFAULT_TYPE
private static final String DEFAULT_TYPE
Default keystore type.
-
-
Method Detail
-
newInstance
public static KeyStore newInstance() throws GeneralSecurityException
Creates a newKeyStore
with the default keystore type and initializes it.- Returns:
- initialized keystore
- Throws:
GeneralSecurityException
- if the keystore cannot be initialized
-
newInstance
public static KeyStore newInstance(char[] password) throws GeneralSecurityException
Creates a newKeyStore
with 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
public static KeyStore newInstance(String type) throws GeneralSecurityException
Creates a newKeyStore
and initializes it.- Parameters:
type
- of keystore instance- Returns:
- initialized keystore
- Throws:
GeneralSecurityException
- if the keystore cannot be initialized
-
newInstance
public static KeyStore newInstance(String type, char[] password) throws GeneralSecurityException
Creates a newKeyStore
and 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
-
-