### Question:
CertUtils { public static byte[] generateCertRequest(PrivateKey privateKey, PublicKey publicKey, String principal) throws NoSuchAlgorithmException, OperatorCreationException, IOException { X500Principal subject = new X500Principal(principal); ContentSigner signGen = new JcaContentSignerBuilder("SHA256withRSA").build(privateKey); PKCS10CertificationRequestBuilder builder = new JcaPKCS10CertificationRequestBuilder(subject, publicKey); PKCS10CertificationRequest csr = builder.build(signGen); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { try (Writer destination = new OutputStreamWriter(output)) { try (JcaPEMWriter pemWriter = new JcaPEMWriter(destination)) { pemWriter.writeObject(csr); } return output.toByteArray(); } } } private  CertUtils(); static String getSubjectCommonName(X509Certificate cert); static String getIssuerCommonName(X509Certificate cert); static String getSubjectSerialNumber(X509Certificate cert); static ClientId getSubjectClientId(X509Certificate cert); static boolean isAuthCert(X509Certificate cert); static boolean isSigningCert(X509Certificate cert); static boolean isValid(X509Certificate cert); static boolean isSelfSigned(X509Certificate cert); static String getOcspResponderUriFromCert(X509Certificate subject); static String[] getCertHashes(List<X509Certificate> certs); static String getRDNValue(X500Name name, ASN1ObjectIdentifier id); static byte[] generateCertRequest(PrivateKey privateKey, PublicKey publicKey, String
            principal); static KeyPair readKeyPairFromPemFile(String filename); static void writePemToFile(byte[] certBytes, String filename); static X509Certificate[] readCertificateChain(String filename); static void createPkcs12(String filenameKey, String filenamePem, String filenameP12); static String identify(X509Certificate certificate);  }### Answer:
@Test public void testGenerateCertRequest() throws NoSuchAlgorithmException, OperatorCreationException, IOException { KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); gen.initialize(2048); KeyPair pair = gen.generateKeyPair(); PrivateKey privateKey = pair.getPrivate(); PublicKey publicKey = pair.getPublic(); byte[] certRequest = CertUtils.generateCertRequest(privateKey, publicKey, "C=FI, CN=foo.bar.com"); assertTrue(certRequest != null && certRequest.length > 0); }