com.ibm.mm.sdk.security
Class KeystoreManager
- java.lang.Object
-
- com.ibm.mm.sdk.security.KeystoreManager
-
public class KeystoreManager extends java.lang.ObjectUtility class for managing RSA keys in Java Keystore (JKS/PKCS12).This class provides methods to:
- Create and initialize keystores
- Store and retrieve RSA key pairs
- Load keys from password-protected keystores
- Generate self-signed certificates for key storage
Usage Example:
// Create a new keystore with RSA key pair KeystoreManager.createKeystore("config/keystore.p12", "keystorePass", "rsa-key", "keyPass"); // Load keys from existing keystore PublicKey publicKey = KeystoreManager.loadPublicKey("config/keystore.p12", "keystorePass", "rsa-key"); PrivateKey privateKey = KeystoreManager.loadPrivateKey("config/keystore.p12", "keystorePass", "rsa-key", "keyPass");- See Also:
RsaEncryptionUtil
-
-
Constructor Summary
Constructors Constructor and Description KeystoreManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static voidcreateKeystore(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias, java.lang.String keyPassword)Create a new keystore with an RSA key pair.static booleankeystoreExists(java.lang.String keystorePath)Check if a keystore file exists.static java.lang.String[]listAliases(java.lang.String keystorePath, java.lang.String keystorePassword)List all aliases in a keystore.static java.security.KeyStoreloadKeystore(java.lang.String keystorePath, java.lang.String keystorePassword)Load a keystore from file.static java.security.PrivateKeyloadPrivateKey(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias, java.lang.String keyPassword)Load a private key from a keystore.static java.security.PublicKeyloadPublicKey(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias)Load a public key from a keystore.static booleanvalidateKeyPassword(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias, java.lang.String keyPassword)Validate key password by attempting to load the private key.static booleanvalidateKeystorePassword(java.lang.String keystorePath, java.lang.String keystorePassword)Validate keystore password by attempting to load the keystore.
-
-
-
Method Detail
-
createKeystore
public static void createKeystore(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias, java.lang.String keyPassword) throws java.lang.ExceptionCreate a new keystore with an RSA key pair.- Parameters:
keystorePath- path where the keystore will be createdkeystorePassword- password to protect the keystorekeyAlias- alias for the key entrykeyPassword- password to protect the private key- Throws:
java.lang.Exception- if keystore creation fails
-
loadPublicKey
public static java.security.PublicKey loadPublicKey(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias) throws java.lang.ExceptionLoad a public key from a keystore.- Parameters:
keystorePath- path to the keystore filekeystorePassword- password to access the keystorekeyAlias- alias of the key entry- Returns:
- PublicKey object
- Throws:
java.lang.Exception- if key loading fails
-
loadPrivateKey
public static java.security.PrivateKey loadPrivateKey(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias, java.lang.String keyPassword) throws java.lang.ExceptionLoad a private key from a keystore.- Parameters:
keystorePath- path to the keystore filekeystorePassword- password to access the keystorekeyAlias- alias of the key entrykeyPassword- password to access the private key- Returns:
- PrivateKey object
- Throws:
java.lang.Exception- if key loading fails
-
loadKeystore
public static java.security.KeyStore loadKeystore(java.lang.String keystorePath, java.lang.String keystorePassword) throws java.lang.ExceptionLoad a keystore from file.- Parameters:
keystorePath- path to the keystore filekeystorePassword- password to access the keystore- Returns:
- KeyStore object
- Throws:
java.lang.Exception- if keystore loading fails
-
keystoreExists
public static boolean keystoreExists(java.lang.String keystorePath)
Check if a keystore file exists.- Parameters:
keystorePath- path to check- Returns:
- true if the keystore file exists
-
listAliases
public static java.lang.String[] listAliases(java.lang.String keystorePath, java.lang.String keystorePassword) throws java.lang.ExceptionList all aliases in a keystore.- Parameters:
keystorePath- path to the keystore filekeystorePassword- password to access the keystore- Returns:
- array of alias names
- Throws:
java.lang.Exception- if keystore loading fails
-
validateKeystorePassword
public static boolean validateKeystorePassword(java.lang.String keystorePath, java.lang.String keystorePassword)Validate keystore password by attempting to load the keystore.- Parameters:
keystorePath- path to the keystore filekeystorePassword- password to validate- Returns:
- true if password is correct
-
validateKeyPassword
public static boolean validateKeyPassword(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias, java.lang.String keyPassword)Validate key password by attempting to load the private key.- Parameters:
keystorePath- path to the keystore filekeystorePassword- password to access the keystorekeyAlias- alias of the key entrykeyPassword- password to validate- Returns:
- true if password is correct
-
-