Package convex.core.crypto
Class PFXTools
java.lang.Object
convex.core.crypto.PFXTools
Utility class for working with Java Key Stores
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyStore
createStore
(File keyFile, String passPhrase) Creates a new PKCS12 key store.static AKeyPair
getKeyPair
(KeyStore ks, String alias, String passphrase) Retrieves a key pair from a key store.static KeyStore
Loads an existing PKCS12 Key store.static KeyStore
Saves a PKCS12 Key store to disk.static KeyStore
setKeyPair
(KeyStore ks, AKeyPair kp, String passPhrase) Adds a key pair to a key store.static KeyStore
setKeyPair
(KeyStore ks, String alias, AKeyPair kp, String passPhrase) Adds a key pair to a key store.
-
Field Details
-
KEYSTORE_TYPE
- See Also:
-
-
Constructor Details
-
PFXTools
public PFXTools()
-
-
Method Details
-
createStore
public static KeyStore createStore(File keyFile, String passPhrase) throws GeneralSecurityException, IOException Creates a new PKCS12 key store.- Parameters:
keyFile
- File to use for creating the key storepassPhrase
- Passphrase used to protect the key store, may be null- Returns:
- New KeyStore instance
- Throws:
GeneralSecurityException
IOException
-
loadStore
public static KeyStore loadStore(File keyFile, String passPhrase) throws IOException, GeneralSecurityException Loads an existing PKCS12 Key store.- Parameters:
keyFile
- File for the existing key storepassPhrase
- Passphrase for decrypting the key store. May be blank or null if not encrypted.- Returns:
- Found key store
- Throws:
IOException
- If an IO error occursGeneralSecurityException
- If a security error occurs
-
saveStore
public static KeyStore saveStore(KeyStore ks, File keyFile, String passPhrase) throws GeneralSecurityException, IOException Saves a PKCS12 Key store to disk.- Parameters:
ks
- Key store to savekeyFile
- Target filepassPhrase
- Passphrase for encrypting the key store. May be blank or null if not need for encryption.- Returns:
- Same key store instance.
- Throws:
IOException
- If an IO error occurs accessing the key storeGeneralSecurityException
- if a security exception occurs
-
getKeyPair
public static AKeyPair getKeyPair(KeyStore ks, String alias, String passphrase) throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException Retrieves a key pair from a key store.- Parameters:
ks
- Key storealias
- Alias used for finding the key pair in the storepassphrase
- Passphrase used for decrypting the key pair. Mandatory.- Returns:
- Found key pair
- Throws:
UnrecoverableKeyException
KeyStoreException
NoSuchAlgorithmException
-
setKeyPair
public static KeyStore setKeyPair(KeyStore ks, AKeyPair kp, String passPhrase) throws IOException, GeneralSecurityException Adds a key pair to a key store.- Parameters:
ks
- Key storekp
- Key pairpassPhrase
- Passphrase for encrypting the key pair. Mandatory.- Returns:
- Updated key store.
- Throws:
IOException
- If an IO error occurs accessing the key storeGeneralSecurityException
- if a security exception occurs
-
setKeyPair
public static KeyStore setKeyPair(KeyStore ks, String alias, AKeyPair kp, String passPhrase) throws IOException, GeneralSecurityException Adds a key pair to a key store.- Parameters:
ks
- Key storealias
- Alias entry for keystorekp
- Key pairpassPhrase
- Passphrase for encrypting the key pair. Mandatory.- Returns:
- Updated key store.
- Throws:
IOException
- If an IO error occurs accessing the key storeGeneralSecurityException
- if a security exception occurs
-