Class KeyStoreUtil
- java.lang.Object
-
- com.github.toolarium.security.keystore.util.KeyStoreUtil
-
public final class KeyStoreUtil extends java.lang.ObjectKeyStoreutil class.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.security.KeyStoreaddCertificateToKeystore(java.security.KeyStore keyStore, java.lang.String inputAlias, java.security.cert.X509Certificate[] certificateChain)Add a certificate chain to the keystorejava.security.KeyStoreaddCertificateToTrustKeystore(java.lang.String alias, java.security.cert.X509Certificate certificate)Add a certificate to the default trust keystorejava.security.KeyStoreaddCertificateToTrustKeystore(java.lang.String alias, java.security.cert.X509Certificate[] certificateChain)Add a certificate chain to the default trust keystorejava.security.KeyStorecreateKeyStore(java.lang.String password)Create a new keystorejava.security.KeyStorecreateKeyStore(java.lang.String fileName, java.lang.String password)Create a new keystorejava.security.KeyStorecreatePKCS12KeyStore(java.lang.String provider, java.lang.String alias, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certificates, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password)Create a PKCS12 key storejava.security.KeyStoregetDefaultTrustKeyStore()Get default trust keystorejavax.net.ssl.TrustManager[]getDefaultTrustManager()Get defaultTrustManager.javax.net.ssl.X509TrustManagergetDefaultX509TrustManager()Get defaultTrustManager.static KeyStoreUtilgetInstance()Get the instancejavax.net.ssl.TrustManager[]getTrustAllCertificateManager()Get aTrustManagerwhich trust all certificatesjava.security.KeyStorereadKeyStore(java.lang.String fileName, java.lang.String type, java.lang.String provider, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password)Read a file as key storeCertificateStorereadPKCS12KeyPair(java.lang.String fileName, java.lang.String provider, java.lang.String alias, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password)Read a PKCS12 file as key storejava.security.KeyStorereadPKCS12KeyStore(java.lang.String fileName, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password)Read a PKCS12 file as key storejava.security.KeyStorereadPKCS12KeyStore(java.lang.String fileName, java.lang.String provider, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password)Read a PKCS12 file as key storejava.security.KeyStorewritePKCS12KeyStore(java.lang.String fileName, java.lang.String provider, java.lang.String alias, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certificates, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password)Writes a PKCS12 file as key storejava.security.KeyStorewritePKCS12KeyStore(java.lang.String fileName, java.lang.String alias, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certificates, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password)Writes a PKCS12 file as key store
-
-
-
Method Detail
-
getInstance
public static KeyStoreUtil getInstance()
Get the instance- Returns:
- the instance
-
createKeyStore
public java.security.KeyStore createKeyStore(java.lang.String password) throws java.security.GeneralSecurityException, java.io.IOExceptionCreate a new keystore- Parameters:
password- the password or null- Returns:
- the new keystore
- Throws:
java.io.IOException- in case of a file read errorjava.security.GeneralSecurityException- in case of error
-
createKeyStore
public java.security.KeyStore createKeyStore(java.lang.String fileName, java.lang.String password) throws java.security.GeneralSecurityException, java.io.IOExceptionCreate a new keystore- Parameters:
fileName- the filenamepassword- the password or null- Returns:
- the new keystore
- Throws:
java.io.IOException- in case of a file read errorjava.security.GeneralSecurityException- in case of error
-
readPKCS12KeyStore
public java.security.KeyStore readPKCS12KeyStore(java.lang.String fileName, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password) throws java.security.GeneralSecurityException, java.io.IOExceptionRead a PKCS12 file as key store- Parameters:
fileName- the file to readpassword- the password or null- Returns:
- the key pairs
- Throws:
java.io.IOException- in case of a file read errorjava.security.GeneralSecurityException- in case of error
-
readPKCS12KeyStore
public java.security.KeyStore readPKCS12KeyStore(java.lang.String fileName, java.lang.String provider, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password) throws java.security.GeneralSecurityException, java.io.IOExceptionRead a PKCS12 file as key store- Parameters:
fileName- the file to readprovider- the provider or nullpassword- the password or null- Returns:
- the key pairs
- Throws:
java.io.IOException- in case of a file read errorjava.security.GeneralSecurityException- in case of error
-
readKeyStore
public java.security.KeyStore readKeyStore(java.lang.String fileName, java.lang.String type, java.lang.String provider, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password) throws java.security.GeneralSecurityException, java.io.IOExceptionRead a file as key store- Parameters:
fileName- the file to readtype- the key store typeprovider- the provider or nullpassword- the password or null- Returns:
- the key pairs
- Throws:
java.io.IOException- in case of a file read errorjava.security.GeneralSecurityException- in case of error
-
readPKCS12KeyPair
public CertificateStore readPKCS12KeyPair(java.lang.String fileName, java.lang.String provider, java.lang.String alias, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password) throws java.security.GeneralSecurityException, java.io.IOException
Read a PKCS12 file as key store- Parameters:
fileName- the file to readprovider- the provider or nullalias- the alias in the PKCS12 filepassword- the password or null- Returns:
- the certificate store
- Throws:
java.security.GeneralSecurityException- in case of errorjava.io.IOException- in case of error
-
writePKCS12KeyStore
public java.security.KeyStore writePKCS12KeyStore(java.lang.String fileName, java.lang.String alias, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certificates, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password) throws java.security.GeneralSecurityException, java.io.IOExceptionWrites a PKCS12 file as key store- Parameters:
fileName- the file to readalias- the alias in the PKCS12 file or nullprivateKey- the private keycertificates- the certificate chainpassword- the password or null- Returns:
- the written key store
- Throws:
java.security.GeneralSecurityException- in case of errorjava.io.IOException- in case of error
-
writePKCS12KeyStore
public java.security.KeyStore writePKCS12KeyStore(java.lang.String fileName, java.lang.String provider, java.lang.String alias, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certificates, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password) throws java.security.GeneralSecurityException, java.io.IOExceptionWrites a PKCS12 file as key store- Parameters:
fileName- the file to readprovider- the provider or nullalias- the alias in the PKCS12 file or nullprivateKey- the private keycertificates- the certificate chainpassword- the password or null- Returns:
- the written key store
- Throws:
java.security.GeneralSecurityException- in case of errorjava.io.IOException- in case of error
-
createPKCS12KeyStore
public java.security.KeyStore createPKCS12KeyStore(java.lang.String provider, java.lang.String alias, java.security.PrivateKey privateKey, java.security.cert.Certificate[] certificates, com.github.toolarium.common.security.ISecuredValue<java.lang.String> password) throws java.security.GeneralSecurityException, java.io.IOExceptionCreate a PKCS12 key store- Parameters:
provider- the provider or nullalias- the alias in the PKCS12 file or nullprivateKey- the private keycertificates- the certificate chainpassword- the password or null- Returns:
- the written key store
- Throws:
java.security.GeneralSecurityException- in case of errorjava.io.IOException- in case of error
-
getDefaultX509TrustManager
public javax.net.ssl.X509TrustManager getDefaultX509TrustManager() throws java.security.GeneralSecurityExceptionGet defaultTrustManager.- Returns:
- the default trust manager or null
- Throws:
java.security.GeneralSecurityException- in case of error
-
getDefaultTrustManager
public javax.net.ssl.TrustManager[] getDefaultTrustManager() throws java.security.GeneralSecurityExceptionGet defaultTrustManager.- Returns:
- the default trust managers
- Throws:
java.security.GeneralSecurityException- in case of error
-
getDefaultTrustKeyStore
public java.security.KeyStore getDefaultTrustKeyStore() throws java.security.GeneralSecurityException, java.io.IOExceptionGet default trust keystore- Returns:
- the trust keystore
- Throws:
java.security.GeneralSecurityException- in case of errorjava.io.IOException- In case of an I/O error
-
addCertificateToTrustKeystore
public java.security.KeyStore addCertificateToTrustKeystore(java.lang.String alias, java.security.cert.X509Certificate certificate) throws java.security.GeneralSecurityException, java.io.IOExceptionAdd a certificate to the default trust keystore- Parameters:
alias- the aliascertificate- the certificate- Returns:
- the keystore
- Throws:
java.security.GeneralSecurityException- In case of general security exceptionjava.io.IOException- In case of not accessable trust keystore
-
addCertificateToTrustKeystore
public java.security.KeyStore addCertificateToTrustKeystore(java.lang.String alias, java.security.cert.X509Certificate[] certificateChain) throws java.security.GeneralSecurityException, java.io.IOExceptionAdd a certificate chain to the default trust keystore- Parameters:
alias- the aliascertificateChain- the certificate chain- Returns:
- the keystore
- Throws:
java.security.GeneralSecurityException- In case of general security exceptionjava.io.IOException- In case of not accessable trust keystore
-
addCertificateToKeystore
public java.security.KeyStore addCertificateToKeystore(java.security.KeyStore keyStore, java.lang.String inputAlias, java.security.cert.X509Certificate[] certificateChain) throws java.security.GeneralSecurityException, java.io.IOExceptionAdd a certificate chain to the keystore- Parameters:
keyStore- the key storeinputAlias- the aliascertificateChain- the certificate chain- Returns:
- the keystore
- Throws:
java.security.GeneralSecurityException- In case of general security exceptionjava.io.IOException- In case of not accessable trust keystore
-
getTrustAllCertificateManager
public javax.net.ssl.TrustManager[] getTrustAllCertificateManager()
Get aTrustManagerwhich trust all certificates- Returns:
TrustManagerwhich trust all certificates
-
-