get Certificate - Java Security

Java examples for Security:Certificate

Description

get Certificate

Demo Code


//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(getCertificate(certFilePath));
    }//from   w ww .j av  a2  s .  co  m

    public static X509Certificate getCertificate(String certFilePath)
            throws FileNotFoundException, CertificateException {
        FileInputStream in = new FileInputStream(certFilePath);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) cf.generateCertificate(in);
        return cert;
    }
}

Related Tutorials