CertificateUtils { public static PKCS10CertificationRequest readCSR(InputStream in) throws IOException { try (PEMParser pemParser = new PEMParser(new InputStreamReader(in, StandardCharsets.US_ASCII))) { Object parsedObj = pemParser.readObject(); if (!(parsedObj instanceof PKCS10CertificationRequest)) { throw new IOException("Not a PKCS10 CSR"); } return (PKCS10CertificationRequest) parsedObj; } } private  CertificateUtils(); static PKCS10CertificationRequest readCSR(InputStream in); static X509Certificate createTlsAlpn01Certificate(KeyPair keypair, Identifier id, byte[] acmeValidation); static X509Certificate createTestRootCertificate(String subject,
            Instant notBefore, Instant notAfter, KeyPair keypair); static X509Certificate createTestIntermediateCertificate(String subject,
            Instant notBefore, Instant notAfter, PublicKey intermediatePublicKey,
            X509Certificate issuer, PrivateKey issuerPrivateKey); static X509Certificate createTestCertificate(PKCS10CertificationRequest csr,
            Instant notBefore, Instant notAfter, X509Certificate issuer, PrivateKey issuerPrivateKey); static final ASN1ObjectIdentifier ACME_VALIDATION; }
@Test public void testReadCSR() throws IOException { KeyPair keypair = KeyPairUtils.createKeyPair(2048); CSRBuilder builder = new CSRBuilder(); builder.addDomains("example.com", "example.org"); builder.sign(keypair); PKCS10CertificationRequest original = builder.getCSR(); byte[] pemFile; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { builder.write(baos); pemFile = baos.toByteArray(); } try (ByteArrayInputStream bais = new ByteArrayInputStream(pemFile)) { PKCS10CertificationRequest read = CertificateUtils.readCSR(bais); assertThat(original.getEncoded(), is(equalTo(read.getEncoded()))); } }