KeyStore is a password-protected file that holds the private key and the certificate. Can be generated from the Keytool tool with the JDK.
But the Keytool tool does not provide a convenient way to get the private keys and certificates from KeyStore files everywhere.
So it is possible to encode the relevant work through the Java.security.KeyStore class provided by the JDK.
[Java] View Plain copy import java.io.file; import java.io.fileinputstream; import java.io.filewriter; import java.security.key; import java.security.keypair; import java.security.keystore; import java.security.keystoreexception; import java.security.nosuchalgorithmexception; import java.security.privatekey; import java.security.publickey; import java.security.unrecoverablekeyexception; import java.security.cert.certificate; import sun.misc.base64encoder; public class exportprivatekey { private File keystoreFile; private String keyStoreType; private char[] password; private String alias; private File exportedFile; public Static keypair getprivatekey (keystore keystore, string alias, char[] Password) { try { &nBsp; 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 (unrecoverablekeyexception e) { } catch (nosuchalgorithmexception e) { } catch (keystoreexception e) { } return null; } &NBsp; public void Export () throws Exception{ keystore keystore=keystore.getinstance (KeyStoreType); base64encoder encoder=new base64encoder (); keystore.load (new FileInputStream (keystorefile), password); keypair keypair=getprivatekey (Keystore,alias, Password); privatekey&nbsP;privatekey=keypair.getprivate (); string encoded=encoder.encode (privateKey.getEncoded ()); filewriter fw=new filewriter (Exportedfile);