com.gridsystems.utils
Class KeyStoreUtils

java.lang.Object
  extended by com.gridsystems.utils.KeyStoreUtils

public final class KeyStoreUtils
extends java.lang.Object

KeyStore Utilities.

Author:
Xmas

Method Summary
static java.lang.String[] addCertificatesToKeyStore(java.lang.String alias, java.security.KeyStore ks, char[] passphrase, java.security.cert.X509Certificate[] certs)
          Add Certificates to KeyStore.
static java.security.KeyStore createEmptyKeyStore(char[] password)
          Create empty KeyStore.
static java.security.cert.X509Certificate[] getCertificatesFromServer(java.lang.String host, int port)
          Gets certificates from server.
static java.security.KeyStore loadKeyStoreFromFile(java.io.File file, char[] passphrase)
          Load KeyStore from File.
static void main(java.lang.String[] args)
          Main method.
static void removeCertificateFromKeyStore(java.security.KeyStore ks, java.lang.String alias)
          Delete Certificate (using alias) from KeyStore.
static void saveKeyStoreToFile(java.io.File file, java.security.KeyStore ks, char[] passphrase)
          Save KeyStore to File.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

saveKeyStoreToFile

public static void saveKeyStoreToFile(java.io.File file,
                                      java.security.KeyStore ks,
                                      char[] passphrase)
                               throws java.security.KeyStoreException,
                                      java.security.NoSuchAlgorithmException,
                                      java.security.cert.CertificateException,
                                      java.io.IOException
Save KeyStore to File.

Parameters:
file - Where store.
ks - Instance of KeyStore
passphrase - Password of KeyStore
Throws:
java.security.KeyStoreException - If the keystore has not been initialised(loaded)
java.security.NoSuchAlgorithmException - If the appropriate data integrity algorithm could not be found
java.security.cert.CertificateException - If any of the certificates included in the keystore data could not be stored
java.io.IOException - If an error occurs storing the keystore

loadKeyStoreFromFile

public static java.security.KeyStore loadKeyStoreFromFile(java.io.File file,
                                                          char[] passphrase)
                                                   throws java.security.KeyStoreException,
                                                          java.security.NoSuchAlgorithmException,
                                                          java.security.cert.CertificateException,
                                                          java.io.IOException
Load KeyStore from File.

Parameters:
file - File where load.
passphrase - Password of KeyStore
Returns:
instance of KeyStore
Throws:
java.security.KeyStoreException - If error
java.io.IOException - If error
java.security.NoSuchAlgorithmException - If error
java.security.cert.CertificateException - If error

getCertificatesFromServer

public static java.security.cert.X509Certificate[] getCertificatesFromServer(java.lang.String host,
                                                                             int port)
                                                                      throws java.security.NoSuchAlgorithmException,
                                                                             java.security.KeyStoreException,
                                                                             java.security.KeyManagementException,
                                                                             java.io.IOException,
                                                                             java.security.cert.CertificateException
Gets certificates from server.

Parameters:
host - Server host
port - Server port
Returns:
List of server certificates
Throws:
java.security.NoSuchAlgorithmException - If error
java.security.KeyStoreException - If error
java.security.KeyManagementException - If error
java.io.IOException - If error
java.security.cert.CertificateException - If error

createEmptyKeyStore

public static java.security.KeyStore createEmptyKeyStore(char[] password)
                                                  throws java.security.KeyStoreException,
                                                         java.security.NoSuchAlgorithmException,
                                                         java.security.cert.CertificateException,
                                                         java.io.IOException
Create empty KeyStore.

Parameters:
password - Password of KeyStore
Returns:
Empty keystore.
Throws:
java.security.KeyStoreException - If error
java.io.IOException - If error
java.security.cert.CertificateException - If error
java.security.NoSuchAlgorithmException - If error

removeCertificateFromKeyStore

public static void removeCertificateFromKeyStore(java.security.KeyStore ks,
                                                 java.lang.String alias)
                                          throws java.security.KeyStoreException
Delete Certificate (using alias) from KeyStore.

Parameters:
ks - KeyStore
alias - Certificate alias.
Throws:
java.security.KeyStoreException - If error

addCertificatesToKeyStore

public static java.lang.String[] addCertificatesToKeyStore(java.lang.String alias,
                                                           java.security.KeyStore ks,
                                                           char[] passphrase,
                                                           java.security.cert.X509Certificate[] certs)
                                                    throws java.security.NoSuchAlgorithmException,
                                                           java.io.IOException,
                                                           java.security.KeyStoreException,
                                                           java.security.cert.CertificateException
Add Certificates to KeyStore.

Parameters:
alias - Certificate alias
passphrase - Password of KeyStore
ks - Instance of KeyStore
certs - List of Certificates to add
Returns:
List of alias added.
Throws:
java.security.NoSuchAlgorithmException - If error
java.io.IOException - If error
java.security.KeyStoreException - If error
java.security.cert.CertificateException - If error

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Main method.

Parameters:
args - Arguments
Throws:
java.lang.Exception - If an error occurs


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.