import java.io.FileInputStream;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.util.Enumeration;
public static void GetPrivateKey() { try{ KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(new FileInputStream("C:\\Program Files\\Java\\jre7\\bin\\xiaoyaodijun.keystore"), "7391428".toCharArray()); KeyPair keyPair = getPrivateKey2(keystore, "xiaoyaodijun.keystore", "7391428".toCharArray()); PrivateKey privateKey = keyPair.getPrivate(); System.out.println("private key = " + privateKey); }catch(Exception ex){} } public static KeyPair getPrivateKey2(KeyStore keystore, String alias, char[] password) { try { Key key=keystore.getKey(alias,password); if(key instanceof PrivateKey) { Certificate cert=keystore.getCertificate(alias); PublicKey publicKey=cert.getPublicKey(); return new KeyPair(publicKey,(PrivateKey)key); } }catch (Exception e) { } return null; }