Skip to content

Commit deea412

Browse files
committed
Use commons-codec instead of jaxb-api
This is needed to remove the dependency from javax.xml.bind
1 parent 38823ef commit deea412

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/com/adyen/util/HMACValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* Adyen Java API Library
1616
*
17-
* Copyright (c) 2017 Adyen B.V.
17+
* Copyright (c) 2026 Adyen B.V.
1818
* This file is open source and available under the MIT license.
1919
* See the LICENSE file for more info.
2020
*/
@@ -31,8 +31,8 @@
3131
import java.util.List;
3232
import javax.crypto.Mac;
3333
import javax.crypto.spec.SecretKeySpec;
34-
import javax.xml.bind.DatatypeConverter;
3534
import org.apache.commons.codec.binary.Base64;
35+
import org.apache.commons.codec.binary.Hex;
3636

3737
/** Utility class for generating and validating HMAC signatures used in Adyen webhooks. */
3838
public class HMACValidator {
@@ -61,7 +61,7 @@ public String calculateHMAC(String data, String key)
6161
throw new IllegalArgumentException("HMAC key is not provided");
6262
}
6363

64-
byte[] rawKey = DatatypeConverter.parseHexBinary(key);
64+
byte[] rawKey = Hex.decodeHex(key);
6565
SecretKeySpec signingKey = new SecretKeySpec(rawKey, HMAC_SHA256_ALGORITHM);
6666

6767
Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);

src/test/java/com/adyen/util/HMACValidatorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,10 @@ public void testCalculateHMACNullKey() {
185185
fail();
186186
}
187187
}
188+
@Test
189+
public void testCalculateHMAC() throws SignatureException {
190+
var hmac = new HMACValidator();
191+
var out = hmac.calculateHMAC("TestPayload", HMAC_KEY);
192+
assertEquals("YA9/UDjldIO4Gq68X4ATYYoEaPYH4f4k2uzBBzEF1PA=", out);
193+
}
188194
}

0 commit comments

Comments
 (0)