| 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, |