|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectbe.fgov.ehealth.etee.crypto.utils.KeyManager
public final class KeyManager
This class provides utility methods to retrieve keys and certificates.
| Nested Class Summary | |
|---|---|
static class |
KeyManager.CertificateRetrievalException
Whenever the retrieval of a certificate has failed. |
static class |
KeyManager.CertStoreException
Whenever we want to build a CertStore and it fails. |
static class |
KeyManager.KeyStoreOpeningException
Whenever the opening of a keyStore fails. |
static class |
KeyManager.KeyStoreStoringException
Whenever we want to store something on a keyStore and it fails. |
| Method Summary | |
|---|---|
static void |
addKey(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword,
java.lang.String alias,
java.security.PrivateKey key,
char[] keyPassword,
java.security.cert.Certificate[] chain)
Adds a key entry to a key store file. |
static void |
emptyKeyStore(java.io.File keyStoreFile,
java.lang.String keyStoreType,
char[] keyStorePassword)
Empties a key store. |
static java.security.cert.X509Certificate |
getCertificate(java.io.File certificateFile)
|
static java.security.cert.X509Certificate |
getCertificate(java.io.InputStream certificateInputstream)
|
static java.security.cert.X509Certificate |
getCertificate(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias)
retrieves the certificate coresponding to the private key alias. |
static java.security.cert.X509Certificate[] |
getCertificateChain(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias)
|
static java.util.List<java.security.cert.X509Certificate> |
getCertificates(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword)
Retrieves all the certificates in a key store. |
static java.util.List<java.security.cert.X509Certificate> |
getCertificates(java.security.KeyStore privateKeyStore)
Retrieves all the certificates in a key store. |
static java.security.cert.CertStore |
getCertStore(java.util.Collection<?> certsAndCrls)
|
static java.util.Map<java.lang.String,java.security.PrivateKey> |
getDecryptionKeys(java.security.KeyStore privateKeyStore,
char[] privateKeyPassword)
Retrieve all the private decryption keys in a private key store where the password is a match for and that have an according encryption certificate containing a key usage that has at least: dataEncipherment and keyEncipherment. |
static java.security.cert.X509Certificate |
getIssuerFromTrustStore(java.security.KeyStore trustStore,
java.security.cert.X509Certificate chainCert)
|
static java.security.PrivateKey |
getKey(java.io.File privateKeyFile)
Creates a PrivateKey object out of a binary file DER encoded. |
static java.security.PrivateKey |
getKey(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
|
static java.security.PrivateKey |
getKey(java.io.InputStream privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
|
static java.security.PrivateKey |
getKey(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
|
static java.security.KeyStore.PrivateKeyEntry |
getKeyAndCertificates(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
Retrieves the private key and corresponding certificate and certificate chain from a key store. |
static java.security.KeyStore |
getKeyStore(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword)
Returns a key store. |
static java.security.KeyStore |
getKeyStore(java.io.InputStream keyStoreIS,
java.lang.String keyStoreType,
char[] keyStorePassword)
|
static java.security.KeyStore |
getKeyStore(java.lang.String privateKeyStoreType)
Returns an empty key store object. |
static java.security.KeyStore |
getKeyStore(java.lang.String keystorePath,
java.lang.String keystoreType,
char[] keystorePassword)
|
static int |
getKeyUsage(java.security.cert.X509Certificate cert)
Gets the X509 extension 'key usage' of a certificate. |
static boolean |
isSelfSigned(java.security.cert.X509Certificate cert)
|
static boolean |
isTrustStoreCert(java.security.KeyStore trustStore,
java.security.cert.X509Certificate chainCert)
|
static boolean |
verifyIssuer(java.security.cert.X509Certificate endCert,
java.security.cert.X509Certificate issuer)
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static java.security.KeyStore getKeyStore(java.lang.String privateKeyStoreType)
privateKeyStoreType -
public static java.security.KeyStore getKeyStore(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword)
throws java.security.cert.CertificateException,
java.io.IOException
privateKeyStoreFile - privateKeyStoreType - privateKeyStorePassword -
KeyManager.KeyStoreOpeningException - (root cause : KeyStoreException) - if a KeyStoreSpi implementation for the specified type is not
available from the specified provider.
KeyManager.KeyStoreOpeningException - (root cause : 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. If the error is due to a wrong password, the cause of the IOException should be an
UnrecoverableKeyException.
java.lang.RuntimeException - when the Bouncy Castle security provider has not been installed.
public static java.security.KeyStore getKeyStore(java.lang.String keystorePath,
java.lang.String keystoreType,
char[] keystorePassword)
keystorePath - keystoreType - keystorePassword -
public static java.security.KeyStore getKeyStore(java.io.InputStream keyStoreIS,
java.lang.String keyStoreType,
char[] keyStorePassword)
throws java.security.cert.CertificateException,
java.io.IOException
keyStoreIS - keyStoreType - keyStorePassword -
KeyManager.KeyStoreOpeningException - (root cause : KeyStoreException) - if a KeyStoreSpi implementation for the specified type is not
available from the specified provider.
KeyManager.KeyStoreOpeningException - (root cause : 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. If the error is due to a wrong password, the cause of the IOException should be an
UnrecoverableKeyException.
java.lang.RuntimeException - when the Bouncy Castle security provider has not been installed.
public static void emptyKeyStore(java.io.File keyStoreFile,
java.lang.String keyStoreType,
char[] keyStorePassword)
throws java.security.cert.CertificateException,
java.io.IOException
keyStoreFile - keyStoreType - keyStorePassword -
java.io.IOException
java.security.cert.CertificateExceptionpublic static java.security.cert.CertStore getCertStore(java.util.Collection<?> certsAndCrls)
public static java.security.PrivateKey getKey(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
throws java.security.UnrecoverableKeyException
privateKeyStore - privateKeyAlias - privateKeyPassword -
java.security.UnrecoverableKeyException
public static java.security.PrivateKey getKey(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
throws java.io.IOException,
java.security.cert.CertificateException,
java.security.UnrecoverableKeyException
privateKeyStoreFile - privateKeyStoreType - privateKeyStorePassword - privateKeyAlias - privateKeyPassword -
java.io.IOException
java.security.cert.CertificateException
java.security.UnrecoverableKeyException
public static java.security.PrivateKey getKey(java.io.InputStream privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
throws java.security.cert.CertificateException,
java.io.IOException,
java.security.UnrecoverableKeyException
privateKeyStoreFile - privateKeyStoreType - "JKS" "PKCS12" ..privateKeyStorePassword - privateKeyAlias - privateKeyPassword -
java.security.KeyStoreException
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
java.io.IOException
java.security.UnrecoverableKeyException
public static java.util.Map<java.lang.String,java.security.PrivateKey> getDecryptionKeys(java.security.KeyStore privateKeyStore,
char[] privateKeyPassword)
privateKeyStore - privateKeyPassword -
java.lang.ClassCastException - when the key store does contain certificates that cannot be parsed to X509Certificate instances.
KeyManager.KeyStoreOpeningException - (KeyStoreException) when the key store was not initialized/loaded before.
public static java.security.KeyStore.PrivateKeyEntry getKeyAndCertificates(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias,
char[] privateKeyPassword)
throws java.security.UnrecoverableKeyException
privateKeyStore - privateKeyAlias - privateKeyPassword -
java.security.UnrecoverableKeyException
KeyManager.KeyStoreOpeningException
public static java.security.PrivateKey getKey(java.io.File privateKeyFile)
throws java.io.IOException,
java.security.spec.InvalidKeySpecException
privateKeyFile -
java.io.IOException - if the file wasn't found
java.security.spec.InvalidKeySpecException - the format of the binary file wasn't expected
public static java.security.cert.X509Certificate getCertificate(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias)
privateKeyStore - privateKeyAlias -
java.lang.ClassCastException - when the key store does contain certificates that cannot be parsed to X509Certificate instances.
public static java.security.cert.X509Certificate getCertificate(java.io.InputStream certificateInputstream)
throws java.security.cert.CertificateException
certificateInputstream - input stream to the certificate file
java.security.cert.CertificateException - When the Certificate could not be parsed.
java.lang.ClassCastException - when the key store does contain certificates that cannot be parsed to X509Certificate instances.
public static java.security.cert.X509Certificate getCertificate(java.io.File certificateFile)
throws java.security.cert.CertificateException,
java.io.FileNotFoundException
certificateFile - certificate file
java.io.FileNotFoundException
java.security.cert.CertificateException
java.lang.ClassCastException - when the key store does contain certificates that cannot be parsed to X509Certificate instances.
public static java.security.cert.X509Certificate[] getCertificateChain(java.security.KeyStore privateKeyStore,
java.lang.String privateKeyAlias)
privateKeyStore - privateKeyAlias -
java.lang.ClassCastException - when the key store does contain certificates that cannot be parsed to X509Certificate instances.
public static java.util.List<java.security.cert.X509Certificate> getCertificates(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword)
throws java.security.cert.CertificateException,
java.io.IOException
privateKeyStoreFile - privateKeyStoreType - privateKeyStorePassword -
java.security.cert.CertificateException
java.io.IOException
java.lang.ClassCastException - when the key store does contain certificates that cannot be parsed to X509Certificate instances.public static java.util.List<java.security.cert.X509Certificate> getCertificates(java.security.KeyStore privateKeyStore)
privateKeyStore -
java.lang.ClassCastException - when the key store does contain certificates that cannot be parsed to X509Certificate instances.
public static void addKey(java.io.File privateKeyStoreFile,
java.lang.String privateKeyStoreType,
char[] privateKeyStorePassword,
java.lang.String alias,
java.security.PrivateKey key,
char[] keyPassword,
java.security.cert.Certificate[] chain)
throws java.security.cert.CertificateException,
java.io.IOException
privateKeyStoreFile - privateKeyStoreType - privateKeyStorePassword - alias - key - keyPassword - chain -
java.security.cert.CertificateException
java.io.IOExceptionpublic static int getKeyUsage(java.security.cert.X509Certificate cert)
cert - the X509 V3 certificate with extensions
public static boolean verifyIssuer(java.security.cert.X509Certificate endCert,
java.security.cert.X509Certificate issuer)
throws java.security.cert.CertificateException
java.security.cert.CertificateException
public static boolean isSelfSigned(java.security.cert.X509Certificate cert)
throws java.security.cert.CertificateException
java.security.cert.CertificateException
public static java.security.cert.X509Certificate getIssuerFromTrustStore(java.security.KeyStore trustStore,
java.security.cert.X509Certificate chainCert)
throws java.security.KeyStoreException
java.security.KeyStoreException
public static boolean isTrustStoreCert(java.security.KeyStore trustStore,
java.security.cert.X509Certificate chainCert)
throws java.security.KeyStoreException
java.security.KeyStoreException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||