File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Security and the fly likes PKCS12 Certificate and Keystore Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "PKCS12 Certificate and Keystore" Watch "PKCS12 Certificate and Keystore" New topic

PKCS12 Certificate and Keystore

Janaki Raju

Joined: Apr 14, 2008
Posts: 8

I am using a PKCS12 certificate file. I am running java 1.5

The following is the code that I use to create a SSL socket and send data.

SSLSocketFactory factory = null;
try {
SSLContext ctx;
KeyManagerFactory kmf;
KeyStore ks;

char[] passphrase = this.keyStorePassword.toCharArray();

ctx = SSLContext.getInstance("SSL");
kmf = KeyManagerFactory.getInstance(keyManagerInstance);

if (keyStoreInstance.length() > 0) {
ks = KeyStore.getInstance(this.keyType, keyStoreInstance);
} else {
ks = KeyStore.getInstance(this.keyType);

ks.load(new FileInputStream(this.keyStore),passphrase);
kmf.init(ks, passphrase);

factory = ctx.getSocketFactory();
} catch (Exception e) {
throw new IOException(e.getMessage());
SSLSocket socket = (SSLSocket)factory.createSocket(path.getHost(),path.getPort());
//Connect using Socket
// This is followed by code to write out the data and then read in the response.

When I run this code, I get an exception - " SSL HandShake Exception - No trusted certificate found". I am not sure how to proceed beyond this. Is there a way I can add the certificate to the keystore? I have tried importing the file to the java truststore- does not seem to work.


I agree. Here's the link:
subject: PKCS12 Certificate and Keystore
It's not a secret anymore!