Skip to content

Instantly share code, notes, and snippets.

@kasimok
Created June 6, 2016 09:21
Show Gist options
  • Save kasimok/cb5833a8b754f74f0675d203d7ca16ab to your computer and use it in GitHub Desktop.
Save kasimok/cb5833a8b754f74f0675d203d7ca16ab to your computer and use it in GitHub Desktop.
Certificate
/**
* Read PEM certificate into javax.security.x509Certificate.
* @param certText
* @return
*/
private X509Certificate readPemCert(String certText) {
CertificateFactory certificateFactory = null;
try {
certificateFactory = CertificateFactory.getInstance("X.509");
} catch (CertificateException e) {
e.printStackTrace();
}
X509Certificate x509cert = null;
InputStream stream = new ByteArrayInputStream(certText.getBytes(StandardCharsets.UTF_8));
try {
x509cert = (X509Certificate) certificateFactory.generateCertificate(stream);
return x509cert;
} catch (CertificateException e) {
e.printStackTrace();
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment