com.ibm.mm.sdk.security

Class KeystoreManager

  • java.lang.Object
    • com.ibm.mm.sdk.security.KeystoreManager


  • public class KeystoreManager
    extends java.lang.Object
    Utility 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 void createKeystore(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 boolean keystoreExists(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.KeyStore loadKeystore(java.lang.String keystorePath, java.lang.String keystorePassword)
      Load a keystore from file.
      static java.security.PrivateKey loadPrivateKey(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.PublicKey loadPublicKey(java.lang.String keystorePath, java.lang.String keystorePassword, java.lang.String keyAlias)
      Load a public key from a keystore.
      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.
      static boolean validateKeystorePassword(java.lang.String keystorePath, java.lang.String keystorePassword)
      Validate keystore password by attempting to load the keystore.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeystoreManager

        public KeystoreManager()
    • 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.Exception
        Create a new keystore with an RSA key pair.
        Parameters:
        keystorePath - path where the keystore will be created
        keystorePassword - password to protect the keystore
        keyAlias - alias for the key entry
        keyPassword - 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.Exception
        Load a public key from a keystore.
        Parameters:
        keystorePath - path to the keystore file
        keystorePassword - password to access the keystore
        keyAlias - 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.Exception
        Load a private key from a keystore.
        Parameters:
        keystorePath - path to the keystore file
        keystorePassword - password to access the keystore
        keyAlias - alias of the key entry
        keyPassword - 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.Exception
        Load a keystore from file.
        Parameters:
        keystorePath - path to the keystore file
        keystorePassword - 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.Exception
        List all aliases in a keystore.
        Parameters:
        keystorePath - path to the keystore file
        keystorePassword - 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 file
        keystorePassword - 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 file
        keystorePassword - password to access the keystore
        keyAlias - alias of the key entry
        keyPassword - password to validate
        Returns:
        true if password is correct
Copyright © 2024 IBM Corporation

Copyright © 2024 IBM Corporation. All rights reserved.