Package es.gob.afirma.utils
Class UtilsKeystore
- java.lang.Object
-
- es.gob.afirma.utils.UtilsKeystore
-
- All Implemented Interfaces:
IUtilsKeystore
public final class UtilsKeystore extends java.lang.Object implements IUtilsKeystore
Class that manages operations related with the management of keystores.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
- Version:
- 1.0, 14/01/2014.
-
-
Field Summary
-
Fields inherited from interface es.gob.afirma.utils.IUtilsKeystore
JCEKS, JKS, PKCS12
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]getCertificateEntry(byte[] keystore, java.lang.String keystoreDecodedPass, java.lang.String alias, java.lang.String keystoreType)Method that obtains a certificate stored inside of a keystore.static java.util.List<java.security.cert.X509Certificate>getListCertificates(byte[] keystore, java.lang.String keystoreDecodedPass, java.lang.String keystoreType)Method that obtains a list with all the certificates stored inside of a keystore.static java.security.PrivateKeygetPrivateKeyEntry(byte[] keystore, java.lang.String keystoreDecodedPass, java.lang.String alias, java.lang.String keystoreType, java.lang.String privateKeyDecodedPass)Method that obtains a private key stored inside of a keystore.static java.security.KeyStoreloadKeystore(java.lang.String path, java.lang.String password, java.lang.String type)Method that loads a keystore.
-
-
-
Method Detail
-
loadKeystore
public static java.security.KeyStore loadKeystore(java.lang.String path, java.lang.String password, java.lang.String type) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOExceptionMethod that loads a keystore.- Parameters:
path- Parameter that represents the path where is located the keystore.password- Parameter that represents the password of the keystore.type- Parameter that represents the keystore type.- Returns:
- an object that represents the loaded keystore.
- Throws:
java.security.KeyStoreException- If no Provider supports a KeyStoreSpi implementation for the specified type.java.security.NoSuchAlgorithmException- If the algorithm used to check the integrity of the keystore cannot be found.java.security.cert.CertificateException- If any of the certificates in the keystore could not be loaded.java.io.IOException- If the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading, or if there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect.
-
getCertificateEntry
public static byte[] getCertificateEntry(byte[] keystore, java.lang.String keystoreDecodedPass, java.lang.String alias, java.lang.String keystoreType) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOExceptionMethod that obtains a certificate stored inside of a keystore.- Parameters:
keystore- Parameter that represents the keystore.keystoreDecodedPass- Parameter that represents the keystore password.alias- Parameter that represents the alias of the certificate to obtain.keystoreType- Parameter that represents the keystore type.- Returns:
- the found certificate.
- Throws:
java.security.KeyStoreException- If no Provider supports a KeyStoreSpi implementation for the specified type, or if the keystore has not been initialized (loaded).java.security.NoSuchAlgorithmException- If the algorithm used to check the integrity of the keystore cannot be found.java.security.cert.CertificateException- If any of the certificates in the keystore could not be loaded.java.io.IOException- If there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect.
-
getListCertificates
public static java.util.List<java.security.cert.X509Certificate> getListCertificates(byte[] keystore, java.lang.String keystoreDecodedPass, java.lang.String keystoreType) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOExceptionMethod that obtains a list with all the certificates stored inside of a keystore.- Parameters:
keystore- Parameter that represents the keystore.keystoreDecodedPass- Parameter that represents the keystore password.keystoreType- Parameter that represents the keystore type.- Returns:
- a list with all the found certificates.
- Throws:
java.security.KeyStoreException- If no Provider supports a KeyStoreSpi implementation for the specified type, or if the keystore has not been initialized (loaded).java.security.NoSuchAlgorithmException- If the algorithm used to check the integrity of the keystore cannot be found.java.security.cert.CertificateException- If any of the certificates in the keystore could not be loaded.java.io.IOException- If there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect.
-
getPrivateKeyEntry
public static java.security.PrivateKey getPrivateKeyEntry(byte[] keystore, java.lang.String keystoreDecodedPass, java.lang.String alias, java.lang.String keystoreType, java.lang.String privateKeyDecodedPass) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOException, java.security.UnrecoverableKeyExceptionMethod that obtains a private key stored inside of a keystore.- Parameters:
keystore- Parameter that represents the keystore.keystoreDecodedPass- Parameter that represents the keystore password.alias- Parameter that represents the alias of the certificate to obtain.keystoreType- Parameter that represents the keystore type.privateKeyDecodedPass- Parameter that represents the private key password.- Returns:
- the found private key.
- Throws:
java.security.KeyStoreException- If if no Provider supports a KeyStoreSpi implementation for the specified type, or if the keystore has not been initialized (loaded).java.security.NoSuchAlgorithmException- If the algorithm used to check the integrity of the keystore cannot be found, or if the algorithm for recovering the key cannot be found.java.security.cert.CertificateException- If any of the certificates in the keystore could not be loaded.java.io.IOException- If there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect.java.security.UnrecoverableKeyException- If the key cannot be recovered (e.g., the given password is wrong).
-
-