@@ -87,9 +87,17 @@ public static Converter<InputStream, RSAPrivateKey> pkcs8() {
8787 "Key is not in PEM-encoded PKCS#8 format, please check that the header begins with "
8888 + PKCS8_PEM_HEADER );
8989 StringBuilder base64Encoded = new StringBuilder ();
90- for (String line : lines ) {
91- if (RsaKeyConverters .isNotPkcs8Wrapper (line )) {
92- base64Encoded .append (line );
90+ if (lines .size () == 1 ) {
91+ base64Encoded .append (lines .get (0 )
92+ .replace (PKCS8_PEM_HEADER , "" )
93+ .replace (PKCS8_PEM_FOOTER , "" )
94+ .replaceAll ("\\ s+" , "" ));
95+ }
96+ else {
97+ for (String line : lines ) {
98+ if (RsaKeyConverters .isNotPkcs8Wrapper (line )) {
99+ base64Encoded .append (line );
100+ }
93101 }
94102 }
95103 byte [] pkcs8 = Base64 .getDecoder ().decode (base64Encoded .toString ());
@@ -165,9 +173,15 @@ private static class X509PemDecoder implements Converter<List<String>, RSAPublic
165173 @ Override
166174 public @ NonNull RSAPublicKey convert (List <String > lines ) {
167175 StringBuilder base64Encoded = new StringBuilder ();
168- for (String line : lines ) {
169- if (isNotX509PemWrapper (line )) {
170- base64Encoded .append (line );
176+ if (lines .size () == 1 ) {
177+ base64Encoded .append (
178+ lines .get (0 ).replace (X509_PEM_HEADER , "" ).replace (X509_PEM_FOOTER , "" ).replaceAll ("\\ s+" , "" ));
179+ }
180+ else {
181+ for (String line : lines ) {
182+ if (isNotX509PemWrapper (line )) {
183+ base64Encoded .append (line );
184+ }
171185 }
172186 }
173187 byte [] x509 = Base64 .getDecoder ().decode (base64Encoded .toString ());
@@ -196,9 +210,17 @@ private static class X509CertificateDecoder implements Converter<List<String>, R
196210 @ Override
197211 public @ NonNull RSAPublicKey convert (List <String > lines ) {
198212 StringBuilder base64Encoded = new StringBuilder ();
199- for (String line : lines ) {
200- if (isNotX509CertificateWrapper (line )) {
201- base64Encoded .append (line );
213+ if (lines .size () == 1 ) {
214+ base64Encoded .append (lines .get (0 )
215+ .replace (X509_CERT_HEADER , "" )
216+ .replace (X509_CERT_FOOTER , "" )
217+ .replaceAll ("\\ s+" , "" ));
218+ }
219+ else {
220+ for (String line : lines ) {
221+ if (isNotX509CertificateWrapper (line )) {
222+ base64Encoded .append (line );
223+ }
202224 }
203225 }
204226 byte [] x509 = Base64 .getDecoder ().decode (base64Encoded .toString ());
0 commit comments