I've stored a certificate as a Base64 encoded string in the database. I can read this from the the database and decode it but I'd like to convert the decoded byte into a X509Certificate. I am looking for sample code to do this. I have tried:
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(bytes);
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
This leads to an issue with the encoding type. A valid sample String or byte that represents a certificate will be good.
Any pointers will be great! Thanks.
Your sample code looks fine. You can generate that
byte yourself using openssl:
openssl genrsa -out privkey.pem openssl req -new -x509 -key privkey.pem -outform DER -out cert.der