CertificateUtils { @VisibleForTesting static byte[] prepareCertificateData(@NotNull String encodedData) { final String formattedData = encodedData.replaceAll("(.{64})", "$1" + LINE_SEPARATOR); return (PEM_CERT_BEGIN_MARKER + LINE_SEPARATOR + formattedData + LINE_SEPARATOR + PEM_CERT_END_MARKER) .getBytes(StandardCharsets.UTF_8); } private  CertificateUtils(); static CertificateFactory createX509CertificateFactory(); static Element buildCertDataFromFile(SupplierWithIO<InputStream> certFileLocation, Document document, CertificateFactory certificateFactory); static Element createCertDataElementFromCert(@NotNull X509Certificate cert, Document document); static Element createCertDataElementFromCert(String issuerName, BigInteger serialNumber, String subjectName, String encodedData, Document document); static void writeCertificateData(@NotNull final File certFolder, @NotNull final String certName, @NotNull final String certEncodedData); static final String PEM_CERT_FILE_EXTENSION; static final String P12_CERT_FILE_EXTENSION; }
@Test void prepareCertificateData() { final byte[] certificateData = CertificateUtils.prepareCertificateData("ENCODED"); assertEquals(PEM_CERT_BEGIN_MARKER + LINE_SEPARATOR + "ENCODED" + LINE_SEPARATOR + PEM_CERT_END_MARKER, new String(certificateData) ); }