Fix CRLF newline removal in DER format logic (#284)

Signed-off-by: Alexander Dümont <alexander_duemont@web.de>
This commit is contained in:
Alexander Dümont 2024-11-18 15:48:49 +01:00 committed by GitHub
parent de8b12c70a
commit 0526ec5d3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -229,8 +229,8 @@ public class CertificateUtils {
// Given a private key in PEM format, encode it as DER
private static byte[] toDerFormat(final byte[] privateKeyPem) throws InvalidKeyException {
String privateKeyAsString = new String(privateKeyPem);
privateKeyAsString = privateKeyAsString.replaceAll("(-+BEGIN PRIVATE KEY-+\\r?\\n|-+END PRIVATE KEY-+\\r?\\n?)", "");
privateKeyAsString = privateKeyAsString.replaceAll("\n", "");
privateKeyAsString = privateKeyAsString.replaceAll("(-+BEGIN PRIVATE KEY-+|-+END PRIVATE KEY-+)", "");
privateKeyAsString = privateKeyAsString.replaceAll("\r?\n", "");
val decoder = Base64.getDecoder();
try {
return decoder.decode(privateKeyAsString);