Java examples for Security:Certificate
populate X509Certificate from a certificate file at the certificate File Path
//package com.java2s; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; public class Main { public static void main(String[] argv) throws Exception { String certFilePath = "java2s.com"; System.out.println(getX509(certFilePath)); }// www . j a v a 2 s.c om /** * populate X509Certificate from a certificate file at the certFilePath */ public static X509Certificate getX509(String certFilePath) throws CertificateException, FileNotFoundException { CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in = new FileInputStream(certFilePath); return (X509Certificate) cf.generateCertificate(in); } }