Import java. Io. fileinputstream;
Import java. Io. ioexception;
Import java. Io. inputstream;
Import java. Security. invalidkeyexception;
Import java. Security. keystore;
Import java. Security. keystoreexception;
Import java. Security. nosuchalgorithmexception;
Import java. Security. nosuchproviderexception;
Import java. Security. privatekey;
Import java. Security. signatureexception;
Import java. Security. unrecoverablekeyexception;
Import java. Security. cert. Certificate;
Import java. Security. cert. certificateexception;
Import java. Security. cert. certificatefactory;
Public class keyreader {
Public static void main (string [] ARGs) throws keystoreexception,
Nosuchproviderexception, nosuchalgorithmexception,
Certificateexception, ioexception, unrecoverablekeyexception,
Invalidkeyexception, signatureexception {
// Open an input stream on the keystore File
String cerfilename = "D:/certa. Cer ";
String p12filename = "D:/certa. p12 ";
String pfxpassword = "OpenSSL ";
Inputstream FCM = new fileinputstream (p12filename );
// Create a keystore object
Keystore = keystore. getinstance ("PKCS12", "BC ");
// Load the file into the keystore
Keystore. Load (FCM, pfxpassword. tochararray ());
String aliaesname = "ABCD ";
Privatekey prikey = (privatekey) (keystore. getkey (aliaesname, null ));
System. Out. println ("Private Key:/N" + prikey );
// Public Key
Inputstream is = new fileinputstream (cerfilename );
Certificatefactory cf = certificatefactory. getinstance ("X509 ");
Certificate cercert = Cf. generatecertificate (is );
System. Out. println ("Public Key:/N" + CERT );
}
}