I have created a self-signed certificate with Java code and added into KeyStore. Now I want to export Private key and Certificate created, into a file in PEM format. Is it
You use Certificate.getEncoded() and Key.getEncoded() to get DER and do the base 64 encoding and header/footer manually, e.g. using DatatypeConverter.printBase64Binary() or some other way. Something like:
certpem = "-----BEGIN CERTIFICATE-----\n" +
DatatypeConverter.printBase64Binary(chain[0].getEncoded())) +
"\n-----END CERTIFICATE-----\n";
keypem = "-----BEGIN RSA PRIVATE KEY-----\n" +
DatatypeConverter.printBase64Binary(privKey.getEncoded())) +
"\n-----END RSA PRIVATE KEY-----\n";