Package com.logicaldoc.sign
Class KeystoreUtil
- java.lang.Object
-
- com.logicaldoc.sign.KeystoreUtil
-
public class KeystoreUtil extends Object
Helper class to handle java keystore and certificates- Since:
- 7.7.2
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description KeystoreUtil(File keyStoreFile, String keyStorePassword, String organizationAlias)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
createNewKeystore(String DN, int validity)
void
exportOrganizationPrivateKeyAndCertificate(File keyFile, File certFile)
void
exportPrivateKeyAndCertificate(String alias, String password, File keyFile, File certFile)
Exports private key and public certificateDate
extractCertExpiration(String alias)
String
extractCertName(String alias)
void
generateUserCertificate(String userAlias, String userFullName, String userPassword, int validity)
File
getKeyStoreFile()
String
getKeyStorePassword()
PrivateKey
getPrivateKey(String alias, String password)
void
removeAlias(String alias)
-
-
-
Method Detail
-
extractCertExpiration
public Date extractCertExpiration(String alias) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException
-
extractCertName
public String extractCertName(String alias) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException
-
removeAlias
public void removeAlias(String alias) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException
-
createNewKeystore
public void createNewKeystore(String DN, int validity) throws IOException
- Throws:
IOException
-
generateUserCertificate
public void generateUserCertificate(String userAlias, String userFullName, String userPassword, int validity) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, InvalidNameException, UnrecoverableKeyException
-
getPrivateKey
public PrivateKey getPrivateKey(String alias, String password) throws IOException
- Throws:
IOException
-
exportPrivateKeyAndCertificate
public void exportPrivateKeyAndCertificate(String alias, String password, File keyFile, File certFile) throws IOException
Exports private key and public certificate- Parameters:
alias
- alias of the certificate in the keystorepassword
- the password to open the keystorekeyFile
- The key file to export(in PKCS12 format)certFile
- The optional public certificate file- Throws:
IOException
- cannot access the certificate inside the keystore
-
exportOrganizationPrivateKeyAndCertificate
public void exportOrganizationPrivateKeyAndCertificate(File keyFile, File certFile) throws IOException
- Throws:
IOException
-
getKeyStoreFile
public File getKeyStoreFile()
-
getKeyStorePassword
public String getKeyStorePassword()
-
-