|
26 | 26 | import java.security.GeneralSecurityException; |
27 | 27 | import java.security.MessageDigest; |
28 | 28 | import java.text.SimpleDateFormat; |
| 29 | +import java.util.Base64; |
29 | 30 | import java.util.Date; |
| 31 | +import java.util.HexFormat; |
30 | 32 | import java.util.Locale; |
31 | 33 |
|
32 | | -import org.apache.commons.codec.binary.Hex; |
33 | 34 | import org.kopi.ebics.interfaces.InitLetter; |
34 | 35 | import org.kopi.ebics.messages.Messages; |
35 | 36 |
|
@@ -103,11 +104,29 @@ protected String getString(String key) { |
103 | 104 | * @throws GeneralSecurityException |
104 | 105 | */ |
105 | 106 | protected byte[] getHash(byte[] certificate) throws GeneralSecurityException { |
106 | | - String hash256 = new String( |
107 | | - Hex.encodeHex(MessageDigest.getInstance("SHA-256").digest(certificate), false)); |
| 107 | + String hash256 = HexFormat.of().withUpperCase().formatHex( |
| 108 | + MessageDigest.getInstance("SHA-256").digest(certificate)); |
108 | 109 | return format(hash256).getBytes(); |
109 | 110 | } |
110 | 111 |
|
| 112 | + /** |
| 113 | + * Encodes {@code data} as MIME Base64 (76-character lines separated by CRLF) |
| 114 | + * with a trailing CRLF, matching the historical commons-codec |
| 115 | + * {@code Base64.encodeBase64(data, true)} byte-for-byte so PEM-style blocks |
| 116 | + * in the letter keep the {@code -----END CERTIFICATE-----} marker on its own line. |
| 117 | + */ |
| 118 | + protected static byte[] chunkedBase64(byte[] data) { |
| 119 | + byte[] encoded = Base64.getMimeEncoder().encode(data); |
| 120 | + if (encoded.length == 0) { |
| 121 | + return encoded; |
| 122 | + } |
| 123 | + byte[] result = new byte[encoded.length + 2]; |
| 124 | + System.arraycopy(encoded, 0, result, 0, encoded.length); |
| 125 | + result[encoded.length] = '\r'; |
| 126 | + result[encoded.length + 1] = '\n'; |
| 127 | + return result; |
| 128 | + } |
| 129 | + |
111 | 130 | /** |
112 | 131 | * Formats a hash 256 input. |
113 | 132 | * @param hash256 the hash input |
|
0 commit comments