Created
October 17, 2017 15:42
-
-
Save alastairmccormack/80b6f9e5c13b3b7db490dd57880f8a22 to your computer and use it in GitHub Desktop.
PEM formatted certificate to java.security.cert.X509Certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bouncycastle.cert.X509CertificateHolder; | |
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; | |
import org.bouncycastle.openssl.PEMParser; | |
import java.security.cert.X509Certificate; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.security.cert.CertificateException; | |
public class PEM2X509Certificate { | |
public X509Certificate loadCert(String fileName) throws IOException, CertificateException { | |
FileReader reader = new FileReader(fileName); | |
PEMParser pemParser = new PEMParser(reader); | |
X509CertificateHolder x509CertificateHolder = (X509CertificateHolder) pemParser.readObject(); | |
X509Certificate x509Certificate = new JcaX509CertificateConverter().getCertificate( x509CertificateHolder ); | |
return x509Certificate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment