5

Is there a way to print the CSR generated with PKCS10CertificationRequest class? I am struggling to see the generated request.

PKCS10CertificationRequest certRequest = new PKCS10CertificationRequest(fromByteArray);
System.out.println("CSR string   = "+certRequest.toString()); 
   
System.out.println("CSR Subject Name  = "+certRequest.getSubject().toString());
System.out.println("CSR Subject PubkeyInfo  = "+certRequest.getSubjectPublicKeyInfo().toString());

1 Answer 1

17

Hope this can help:

PemObject pemObject = new PemObject("CERTIFICATE REQUEST", certRequest.getEncoded());
StringWriter str = new StringWriter();
PEMWriter pemWriter = new PEMWriter(str);
pemWriter.writeObject(pemObject);
pemWriter.close();
str.close();
System.out.println(str);
2
  • Just a comment for users of older BouncyCastle. There is no PemObject, so pass the CSR directly to pemWriter#writeObject
    – banterCZ
    Mar 11, 2015 at 9:31
  • PEMWriter is depricated. So, Use JcaPEMWriter instead. Feb 18, 2021 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.