Here you can find the source of getPublicKeyFromFile(File cert, String alias, String password)
public static PublicKey getPublicKeyFromFile(File cert, String alias, String password) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.security.Key; import java.security.KeyStore; import java.security.PublicKey; import java.security.cert.Certificate; public class Main { public static PublicKey getPublicKeyFromFile(File cert, String alias, String password) throws Exception { KeyStore ks = KeyStore.getInstance("JKS"); char[] pwd = password.toCharArray(); InputStream is = new FileInputStream(cert); ks.load(is, pwd);// w w w. j ava2 s. c o m Key key = ks.getKey(alias, pwd); Certificate c = ks.getCertificate(alias); PublicKey p = c.getPublicKey(); return p; } }