Here you can find the source of getPublicKey(KeyStore keyStore, String alias, char[] password)
public static PublicKey getPublicKey(KeyStore keyStore, String alias, char[] password) throws GeneralSecurityException
//package com.java2s; //License from project: Open Source License import java.security.GeneralSecurityException; import java.security.Key; import java.security.KeyStore; import java.security.PrivateKey; import java.security.PublicKey; import java.security.cert.Certificate; public class Main { public static PublicKey getPublicKey(KeyStore keyStore, String alias, char[] password) throws GeneralSecurityException { PublicKey publicKey = null; // Get private key Key key = keyStore.getKey(alias, password); if (key instanceof PrivateKey) { // Get certificate of public key Certificate cert = keyStore.getCertificate(alias); // Get public key publicKey = cert.getPublicKey(); }/*from w ww .j a v a 2s .c o m*/ // if alias is a certificate alias, get the public key from the // certificate. if (publicKey == null) { Certificate cert = keyStore.getCertificate(alias); if (cert != null) publicKey = cert.getPublicKey(); } return publicKey; } }