Class CertificateManagementService
- java.lang.Object
-
- org.codehaus.mojo.keytool.services.CertificateManagementService
-
@Named @Singleton public class CertificateManagementService extends java.lang.ObjectService for managing certificates in keystores using Java KeyStore API. Follows Single Responsibility Principle (SOLID-S).- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description CertificateManagementService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeleteAlias(java.io.File keystoreFile, java.lang.String keystoreType, char[] keystorePassword, java.lang.String alias)Delete an alias from keystore.voidexportCertificate(java.io.File keystoreFile, java.lang.String keystoreType, char[] keystorePassword, java.lang.String alias, java.io.File outputFile)Export a certificate from keystore to file.voidimportCertificate(java.io.File keystoreFile, java.lang.String keystoreType, char[] keystorePassword, java.lang.String alias, java.io.File certificateFile, boolean skipIfAliasExists, char[] keyPassword)Import a certificate into a keystore.private java.security.cert.CertificateloadCertificate(java.io.File certificateFile)Load certificate from file.private java.security.KeyStoreloadOrCreateKeyStore(java.io.File keystoreFile, java.lang.String keystoreType, char[] password)Load or create keystore.private voidsaveKeyStore(java.security.KeyStore keystore, java.io.File keystoreFile, char[] password)Save keystore to file.
-
-
-
Method Detail
-
importCertificate
public void importCertificate(java.io.File keystoreFile, java.lang.String keystoreType, char[] keystorePassword, java.lang.String alias, java.io.File certificateFile, boolean skipIfAliasExists, char[] keyPassword) throws java.security.KeyStoreException, java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionImport a certificate into a keystore.This method supports two scenarios:
- Importing a trusted certificate (new alias or replacing a trusted certificate)
- Importing a certificate reply to replace the certificate chain of an existing key pair
- Parameters:
keystoreFile- keystore filekeystoreType- keystore type (e.g., "JKS", "PKCS12")keystorePassword- keystore passwordalias- certificate aliascertificateFile- certificate file to importskipIfAliasExists- if true, skip import if alias already existskeyPassword- password for the private key (if different from keystore password); may be null- Throws:
java.security.KeyStoreException- if keystore operation failsjava.io.IOException- if file operations failjava.security.NoSuchAlgorithmException- if algorithm is not availablejava.security.cert.CertificateException- if certificate is invalid
-
exportCertificate
public void exportCertificate(java.io.File keystoreFile, java.lang.String keystoreType, char[] keystorePassword, java.lang.String alias, java.io.File outputFile) throws java.lang.ExceptionExport a certificate from keystore to file.- Parameters:
keystoreFile- keystore filekeystoreType- keystore typekeystorePassword- keystore passwordalias- certificate aliasoutputFile- output file for certificate- Throws:
java.lang.Exception- if operation fails
-
deleteAlias
public void deleteAlias(java.io.File keystoreFile, java.lang.String keystoreType, char[] keystorePassword, java.lang.String alias) throws java.lang.ExceptionDelete an alias from keystore.- Parameters:
keystoreFile- keystore filekeystoreType- keystore typekeystorePassword- keystore passwordalias- alias to delete- Throws:
java.lang.Exception- if operation fails
-
loadOrCreateKeyStore
private java.security.KeyStore loadOrCreateKeyStore(java.io.File keystoreFile, java.lang.String keystoreType, char[] password) throws java.security.KeyStoreException, java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionLoad or create keystore.- Throws:
java.security.KeyStoreExceptionjava.io.IOExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateException
-
loadCertificate
private java.security.cert.Certificate loadCertificate(java.io.File certificateFile) throws java.io.IOException, java.security.cert.CertificateExceptionLoad certificate from file.- Throws:
java.io.IOExceptionjava.security.cert.CertificateException
-
saveKeyStore
private void saveKeyStore(java.security.KeyStore keystore, java.io.File keystoreFile, char[] password) throws java.security.KeyStoreException, java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionSave keystore to file.- Throws:
java.security.KeyStoreExceptionjava.io.IOExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateException
-
-