Package org.picketbox.util
Class KeyStoreUtil
- java.lang.Object
-
- org.picketbox.util.KeyStoreUtil
-
public class KeyStoreUtil extends Object
Utility to handle Java Keystore- Since:
- Jan 12, 2009
- Author:
- Anil.Saldhana@redhat.com, Peter Skopek (pskopek_at_redhat_dot_com)
-
-
Constructor Summary
Constructors Constructor Description KeyStoreUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addCertificate(File keystoreFile, char[] storePass, String alias, Certificate cert)
Add a certificate to the KeyStorestatic void
addCertificate(String keyStoreType, File keystoreFile, char[] storePass, String alias, Certificate cert)
Add a certificate to the KeyStorestatic KeyStore
createKeyStore(String keyStoreType, char[] keyStorePWD)
Create new empty keystore with specified keyStoreType and keyStorePWDstatic KeyPair
generateKeyPair(String algo)
Generate a Key Pairstatic KeyStore
getKeyStore(File keyStoreFile, char[] storePass)
Get the KeyStorestatic KeyStore
getKeyStore(InputStream ksStream, char[] storePass)
Get the Key Store Note: This method wants the InputStream to be not null.static KeyStore
getKeyStore(String fileURL, char[] storePass)
Get the Keystore given the url to the keystore file as a stringstatic KeyStore
getKeyStore(String keyStoreType, File keyStoreFile, char[] storePass)
Get the KeyStorestatic KeyStore
getKeyStore(String keyStoreType, InputStream ksStream, char[] storePass)
Get the Key Store Note: This method wants the InputStream to be not null.static KeyStore
getKeyStore(String keyStoreType, String fileURL, char[] storePass)
Get the Keystore given the url to the keystore file as a stringstatic KeyStore
getKeyStore(String keyStoreType, URL url, char[] storePass)
Get the Keystore given the URL to the keystorestatic KeyStore
getKeyStore(URL url, char[] storePass)
Get the Keystore given the URL to the keystorestatic KeyPair
getPrivateKey(KeyStore keystore, String alias, char[] password)
Get the key pair from the keystorestatic PublicKey
getPublicKey(KeyStore ks, String alias, char[] password)
Get the Public Key from the keystore
-
-
-
Method Detail
-
getKeyStore
public static KeyStore getKeyStore(File keyStoreFile, char[] storePass) throws GeneralSecurityException, IOException
Get the KeyStore- Parameters:
keyStoreFile
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
-
getKeyStore
public static KeyStore getKeyStore(String fileURL, char[] storePass) throws GeneralSecurityException, IOException
Get the Keystore given the url to the keystore file as a string- Parameters:
fileURL
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
-
getKeyStore
public static KeyStore getKeyStore(URL url, char[] storePass) throws GeneralSecurityException, IOException
Get the Keystore given the URL to the keystore- Parameters:
url
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
-
getKeyStore
public static KeyStore getKeyStore(InputStream ksStream, char[] storePass) throws GeneralSecurityException, IOException
Get the Key Store Note: This method wants the InputStream to be not null.- Parameters:
ksStream
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
IllegalArgumentException
- if ksStream is null
-
getKeyStore
public static KeyStore getKeyStore(String keyStoreType, File keyStoreFile, char[] storePass) throws GeneralSecurityException, IOException
Get the KeyStore- Parameters:
keyStoreType
- or null for defaultkeyStoreFile
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
-
getKeyStore
public static KeyStore getKeyStore(String keyStoreType, String fileURL, char[] storePass) throws GeneralSecurityException, IOException
Get the Keystore given the url to the keystore file as a string- Parameters:
keyStoreType
- or null for defaultfileURL
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
-
getKeyStore
public static KeyStore getKeyStore(String keyStoreType, URL url, char[] storePass) throws GeneralSecurityException, IOException
Get the Keystore given the URL to the keystore- Parameters:
keyStoreType
- or null for defaulturl
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
-
getKeyStore
public static KeyStore getKeyStore(String keyStoreType, InputStream ksStream, char[] storePass) throws GeneralSecurityException, IOException
Get the Key Store Note: This method wants the InputStream to be not null.- Parameters:
keyStoreType
- or null for defaultksStream
-storePass
-- Returns:
- Throws:
GeneralSecurityException
IOException
IllegalArgumentException
- if ksStream is null
-
generateKeyPair
public static KeyPair generateKeyPair(String algo) throws GeneralSecurityException
Generate a Key Pair- Parameters:
algo
- (RSA, DSA etc)- Returns:
- Throws:
GeneralSecurityException
-
getPublicKey
public static PublicKey getPublicKey(KeyStore ks, String alias, char[] password) throws KeyStoreException, NoSuchAlgorithmException, GeneralSecurityException
Get the Public Key from the keystore- Parameters:
ks
-alias
-password
-- Returns:
- Throws:
GeneralSecurityException
KeyStoreException
NoSuchAlgorithmException
-
addCertificate
public static void addCertificate(File keystoreFile, char[] storePass, String alias, Certificate cert) throws GeneralSecurityException, IOException
Add a certificate to the KeyStore- Parameters:
keystoreFile
-storePass
-alias
-cert
-- Throws:
GeneralSecurityException
IOException
-
addCertificate
public static void addCertificate(String keyStoreType, File keystoreFile, char[] storePass, String alias, Certificate cert) throws GeneralSecurityException, IOException
Add a certificate to the KeyStore- Parameters:
keystoreFile
-storePass
-alias
-cert
-- Throws:
GeneralSecurityException
IOException
-
getPrivateKey
public static KeyPair getPrivateKey(KeyStore keystore, String alias, char[] password) throws Exception
Get the key pair from the keystore- Parameters:
keystore
-alias
-password
-- Returns:
- Throws:
Exception
-
-