Here you can find the source of getPublicKey(String certPath)
public static PublicKey getPublicKey(String certPath) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.FileInputStream; import java.io.InputStream; import java.security.PublicKey; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; public class Main { public static PublicKey getPublicKey(String certPath) throws Exception { Certificate cert = getCert(certPath); return cert.getPublicKey(); }/*from ww w .j a v a2s . co m*/ public static Certificate getCert(String certPath) throws Exception { InputStream streamCert = new FileInputStream(certPath); CertificateFactory factory = CertificateFactory.getInstance("X.509"); Certificate cert = factory.generateCertificate(streamCert); return cert; } }