For Programmers: Free Programming Magazines  


Home > Archive > Java Security > November 2005 > How to get private key from *.pfx certificate file?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to get private key from *.pfx certificate file?
quangdvh

2005-11-08, 11:44 pm

try { //get keystore
ks = KeyStore.getInstance("PKCS12";
password = "1234".toCharArray();
ks.load(new FileInputStream("hoa.pfx"), password);
System.out.print("OK");
} catch (Exception e) {
System.out.println(e.toString());
return ;
}

PrivateKey privatekey = null;
PublicKey publickey = null;

try { //get key
Enumeration en = ks.aliases();
String ALIAS = "";
Vector vectaliases = new Vector();

while (en.hasMoreElements())
vectaliases.add(en.nextElement());
String[] aliases = (String []) (vectaliases.toArray(new String[0]));
for (int i = 0; i < aliases.length; i++)
if (ks.isKeyEntry(aliases[i]))
{
ALIAS = aliases[i];
break;
}

privatekey = (PrivateKey)ks.getKey(ALIAS, password);
System.out.println(privatekey.toString());
cert = (X509Certificate)ks.getCertificate(ALIAS);
publickey = ks.getCertificate(ALIAS).getPublicKey();
} catch (Exception e) {
e.printStackTrace();
return ;
}




This code run under JDK 1.4 OK but not run under JDK 1.2

How to do it under JDK 1.2.2?
Can you help me and email to me.
quangdvh@gmail.com
Thanks,
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com