KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > protocol > ws > common > KeyStoreHelper


1 package org.ejbca.core.protocol.ws.common;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.security.KeyStoreException JavaDoc;
6 import java.security.NoSuchAlgorithmException JavaDoc;
7 import java.security.NoSuchProviderException JavaDoc;
8 import java.security.cert.CertificateException JavaDoc;
9
10 import org.ejbca.util.Base64;
11
12
13 /**
14  * Class used to generate a java.security.KeyStore from a
15  * org.ejbca.core.protocol.ws.common.KeyStore
16  *
17  * @author Philip Vendil
18  *
19  * $id$
20  */

21
22 public class KeyStoreHelper {
23
24     /**
25      * Retrieves the keystore from the encoded data.
26      * @param type "PKCS12" or "JKS"
27      * @param password to lock the keystore
28      * @return the loaded and unlocked keystore.
29      * @throws CertificateException
30      * @throws IOException
31      * @throws NoSuchAlgorithmException
32      * @throws NoSuchProviderException
33      * @throws KeyStoreException
34      */

35     public static java.security.KeyStore JavaDoc getKeyStore(byte[] keystoreData, String JavaDoc type, String JavaDoc password) throws CertificateException JavaDoc, NoSuchAlgorithmException JavaDoc, IOException JavaDoc, KeyStoreException JavaDoc, NoSuchProviderException JavaDoc{
36         java.security.KeyStore JavaDoc ks = java.security.KeyStore.getInstance(type, "BC");
37         ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(Base64.decode(keystoreData));
38         ks.load(bais, password.toCharArray());
39         return ks;
40     }
41 }
42
Popular Tags