KeyStoreManager

public class KeyStoreManager extends KeyStoreComponent

KeyStoreManager manages a key store and provides convenient methods such as method that retrieves an X509Certificate or retrieves a private key.

Author:Hugo Y. K. Lam

Constructors

KeyStoreManager

public KeyStoreManager()

Creates a new instance of KeyStoreManager.

KeyStoreManager

public KeyStoreManager(KeyStore keyStore)

Creates a new instance of KeyStoreManager.

Parameters:
  • keyStore – the initialized keystore to be managed.
Throws:
  • KeyStoreManagementException – if the specified key store is null.

KeyStoreManager

public KeyStoreManager(KeyStore keyStore, String alias, String keyPass)

Creates a new instance of KeyStoreManager.

Parameters:
  • keyStore – the initialized keystore to be managed.
  • alias – the alias name associating with the managed key.
  • keyPass – the key password.
Throws:
  • KeyStoreManagementException – if the specified key store is null.

KeyStoreManager

public KeyStoreManager(String location, String storePass)

Creates a new instance of KeyStoreManager.

Parameters:
  • location – the key store location.
  • storePass – the key store password.
Throws:
  • KeyStoreManagementException – if unable to initialize the key store with the given paramemeters.

KeyStoreManager

public KeyStoreManager(String location, String storePass, String alias, String keyPass)

Creates a new instance of KeyStoreManager.

Parameters:
  • location – the key store location.
  • storePass – the key store password.
  • alias – the alias name.
  • keyPass – the key password.
Throws:
  • KeyStoreManagementException – if unable to initialize the key store with the given paramemeters.

KeyStoreManager

public KeyStoreManager(String location, String storePass, String storeType, Object provider)

Creates a new instance of KeyStoreManager.

Parameters:
  • location – the key store location.
  • storePass – the key store password.
  • storeType – the key store type.
  • provider – the key store provider.
Throws:
  • KeyStoreManagementException – if unable to initialize the key store with the given paramemeters.

KeyStoreManager

public KeyStoreManager(String location, String storePass, String alias, String keyPass, String storeType, Object provider)

Creates a new instance of KeyStoreManager.

Parameters:
  • location – the key store location.
  • storePass – the key store password.
  • alias – the alias name.
  • keyPass – the key password.
  • storeType – the key store type.
  • provider – the key store provider.
Throws:
  • KeyStoreManagementException – if unable to initialize the key store with the given paramemeters.

Methods

getAlias

public String getAlias()

Gets the managed alias.

Returns:the managed alias.

getAliases

public String[] getAliases()

Gets all the aliases in the managed key store.

Returns:all the aliases in the managed key store.

getCertificate

public Certificate getCertificate()

Gets the managed certificate.

Returns:the managed certificate.

getCertificate

public Certificate getCertificate(String alias)

Gets the certificate asscoiated with the given alias name.

Parameters:
  • alias – the alias name.
Returns:

the certificate.

getCertificateChain

public Certificate[] getCertificateChain()

Gets the managed certificate chain.

Returns:the managed certificate chain.

getCertificateChain

public Certificate[] getCertificateChain(String alias)

Gets the certificate chain asscoiated with the given alias name.

Parameters:
  • alias – the alias name.
Returns:

the certificate chain.

getKeyStore

public KeyStore getKeyStore()

Gets the managed key store.

Returns:the key store.

getPrivateKey

public PrivateKey getPrivateKey()

Gets the managed private key.

Throws:
  • NoSuchAlgorithmException – if the algorithm for recovering the key cannot be found.
  • UnrecoverableKeyException – if the key cannot be recovered (e.g., the given password is wrong).
Returns:

the private key.

getPublicKey

public PublicKey getPublicKey()

Gets the managed public key.

Returns:the public key.

getX509Certificate

public X509Certificate getX509Certificate()

Gets the managed X509 certificate.

Throws:
Returns:

the managed X509 certificate.

getX509Certificate

public X509Certificate getX509Certificate(String alias)

Gets the managed X509 certificate.

Parameters:
  • alias – the alias name.
Throws:
Returns:

the managed X509 certificate.

getX509CertificateChain

public X509Certificate[] getX509CertificateChain()

Gets the managed X509 certificate chain.

Returns:the managed certificate chain.

getX509CertificateChain

public X509Certificate[] getX509CertificateChain(String alias)

Gets the X509 certificate chain asscoiated with the given alias name.

Parameters:
  • alias – the alias name.
Returns:

the certificate chain.

isCertificateTrusted

public boolean isCertificateTrusted()

Checks if the managed certificate is trusted.

Returns:true if the managed certificate is trusted.

isCertificateTrusted

public boolean isCertificateTrusted(String alias)

Checks if the certificate asscoiated with the given alias name is trusted.

Returns:true the certificate is trusted.