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);
Sign up to request clarification or add additional context in comments.

2 Comments

Just a comment for users of older BouncyCastle. There is no PemObject, so pass the CSR directly to pemWriter#writeObject
PEMWriter is depricated. So, Use JcaPEMWriter instead.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.