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 voidaddCertificate(File keystoreFile, char[] storePass, String alias, Certificate cert)Add a certificate to the KeyStorestatic voidaddCertificate(String keyStoreType, File keystoreFile, char[] storePass, String alias, Certificate cert)Add a certificate to the KeyStorestatic KeyStorecreateKeyStore(String keyStoreType, char[] keyStorePWD)Create new empty keystore with specified keyStoreType and keyStorePWDstatic KeyPairgenerateKeyPair(String algo)Generate a Key Pairstatic KeyStoregetKeyStore(File keyStoreFile, char[] storePass)Get the KeyStorestatic KeyStoregetKeyStore(InputStream ksStream, char[] storePass)Get the Key Store Note: This method wants the InputStream to be not null.static KeyStoregetKeyStore(String fileURL, char[] storePass)Get the Keystore given the url to the keystore file as a stringstatic KeyStoregetKeyStore(String keyStoreType, File keyStoreFile, char[] storePass)Get the KeyStorestatic KeyStoregetKeyStore(String keyStoreType, InputStream ksStream, char[] storePass)Get the Key Store Note: This method wants the InputStream to be not null.static KeyStoregetKeyStore(String keyStoreType, String fileURL, char[] storePass)Get the Keystore given the url to the keystore file as a stringstatic KeyStoregetKeyStore(String keyStoreType, URL url, char[] storePass)Get the Keystore given the URL to the keystorestatic KeyStoregetKeyStore(URL url, char[] storePass)Get the Keystore given the URL to the keystorestatic KeyPairgetPrivateKey(KeyStore keystore, String alias, char[] password)Get the key pair from the keystorestatic PublicKeygetPublicKey(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:
GeneralSecurityExceptionIOException
-
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:
GeneralSecurityExceptionIOException
-
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:
GeneralSecurityExceptionIOException
-
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:
GeneralSecurityExceptionIOExceptionIllegalArgumentException- 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:
GeneralSecurityExceptionIOException
-
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:
GeneralSecurityExceptionIOException
-
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:
GeneralSecurityExceptionIOException
-
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:
GeneralSecurityExceptionIOExceptionIllegalArgumentException- 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:
GeneralSecurityExceptionKeyStoreExceptionNoSuchAlgorithmException
-
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:
GeneralSecurityExceptionIOException
-
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:
GeneralSecurityExceptionIOException
-
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
-
-