FileDocCategorySizeDatePackage
Utils.javaAPI DocExample878Mon Nov 25 08:50:08 GMT 2002ora.jwsnut.chapter7.util

Utils.java

package ora.jwsnut.chapter7.util;

import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import javax.security.auth.x500.X500PrivateCredential;

// Utilies used with the registry examples
public class Utils {

    // Gets the credentials for a given alias and keystore file
    public static X500PrivateCredential getCredentials(String file, String alias, 
						String keyPassword, String storePassword) throws Throwable {
        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load(new FileInputStream(file), storePassword.toCharArray());
        X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
        PrivateKey key = (PrivateKey)ks.getKey(alias, keyPassword.toCharArray());
        return new X500PrivateCredential(cert, key, alias);
    }
}