Skip to content

Commit 6928f67

Browse files
authored
Remove any combination of CR/LF line endings when reading private key from PEM
RFC 7468 permits LF, CR or CRLF line endings in PEM files. Current code first removes LF (\n) and then tries to remove CRLF (\r\n), so the CR (\n) characters are left in the file and key Base64 cannot be decoded. Because of this private key files generated/saved on Windows with CRLF line endings cannot be loaded into library.
1 parent d651388 commit 6928f67

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/java/com/mastercard/developer/utils/EncryptionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static PrivateKey loadDecryptionKey(InputStream keyDataStream) throws Gen
6464
keyDataString = keyDataString.replace(PKCS_1_PEM_HEADER, "");
6565
keyDataString = keyDataString.replace(PKCS_1_PEM_FOOTER, "");
6666
keyDataString = keyDataString.replace("\n", "");
67-
keyDataString = keyDataString.replace("\r\n", "");
67+
keyDataString = keyDataString.replace("\r", "");
6868
return readPkcs1PrivateKey(base64Decode(keyDataString));
6969
}
7070

@@ -73,7 +73,7 @@ public static PrivateKey loadDecryptionKey(InputStream keyDataStream) throws Gen
7373
keyDataString = keyDataString.replace(PKCS_8_PEM_HEADER, "");
7474
keyDataString = keyDataString.replace(PKCS_8_PEM_FOOTER, "");
7575
keyDataString = keyDataString.replace("\n", "");
76-
keyDataString = keyDataString.replace("\r\n", "");
76+
keyDataString = keyDataString.replace("\r", "");
7777
return readPkcs8PrivateKey(base64Decode(keyDataString));
7878
}
7979

0 commit comments

Comments
 (0)