// fetch a certificate from a PKCS12 certificate KeyStore ks = KeyStore.getInstance ( "PKCS12" ); // for security, KeyStore wants certificate password as char[] char[] password = "Sesame".toCharArray(); ks.load( new FileInputStream( "yourcert.p12" ), password ); Certificate c = ks.getCertificate( "thecert" ); PublicKey p = c.getPublicKey(); // To fetch a certificate from .keystore use KeyStore ks = Keystore.getInstance ( "JKS" ); // instead instead of .getInstance ( "PKCS12" )