Package convex.core.crypto
Class PFXTools
java.lang.Object
convex.core.crypto.PFXTools
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Certificate
createSelfSignedCertificate(AKeyPair kpToSign)
Generates a self-signed certificate.static 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:
- Constant Field Values
-
CERTIFICATE_ALGORITHM
- See Also:
- Constant Field Values
-
-
Constructor Details
-
PFXTools
public PFXTools()
-
-
Method Details
-
createStore
public static KeyStore createStore(File keyFile, String passPhrase) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateExceptionCreates 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:
KeyStoreException
IOException
NoSuchAlgorithmException
CertificateException
-
loadStore
public static KeyStore loadStore(File keyFile, String passPhrase) throws IOException, GeneralSecurityExceptionLoads 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, IOExceptionSaves 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
-
createSelfSignedCertificate
public static Certificate createSelfSignedCertificate(AKeyPair kpToSign) throws GeneralSecurityExceptionGenerates a self-signed certificate.- Parameters:
kpToSign
- Key pair- Returns:
- New certificate
- Throws:
GeneralSecurityException
- If a security exception occurs
-
getKeyPair
public static AKeyPair getKeyPair(KeyStore ks, String alias, String passPhrase) throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmExceptionRetrieves 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, GeneralSecurityExceptionAdds 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, GeneralSecurityExceptionAdds 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
-