# KeyUtil.java Sample

This topic inludes the source code for the KeyUtil.java Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/ProxyClient/WSSE/clientCert/

## Sample Source Code

`01 package WSSE.clientCert; 02 03 import java.io.IOException; 04 import java.io.FileInputStream; 05 import java.security.KeyStore; 06 import java.security.PrivateKey; 07 import java.security.KeyStoreException; 08 import java.security.NoSuchAlgorithmException; 09 import java.security.cert.X509Certificate; 10 import java.security.cert.CertificateException; 11 12 public class KeyUtil { 13 14 public static KeyStore loadKeystore(String filename, String password) 15 throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { 16 final KeyStore ks = KeyStore.getInstance("JKS"); 17 ks.load(new FileInputStream(filename), password.toCharArray()); 18 return ks; 19 } 20 21 public static PrivateKey getPrivateKey(String alias, String password, KeyStore keystore) 22 throws Exception { 23 PrivateKey result = 24 (PrivateKey) keystore.getKey(alias, password.toCharArray()); 25 26 return result; 27 } 28 29 public static X509Certificate getCertificate(String alias, KeyStore keystore) 30 throws Exception { 31 X509Certificate result = (X509Certificate) keystore.getCertificate(alias); 32 return result; 33 } 34 35 }`