Class HMACValidator


  • public class HMACValidator
    extends Object
    Utility class for generating and validating HMAC signatures used in Adyen webhooks.
    • Field Detail

      • DATA_SEPARATOR

        public static final String DATA_SEPARATOR
        Separator used when joining data for signature calculation.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HMACValidator

        public HMACValidator()
    • Method Detail

      • validateHMAC

        public boolean validateHMAC​(String hmacSignature,
                                    String hmacKey,
                                    String payload)
                             throws SignatureException
        Validates an HMAC signature for generic webhooks (e.g. Banking, Management).
        Parameters:
        hmacSignature - the signature received in the webhook
        hmacKey - the configured HMAC key
        payload - the payload string used for HMAC calculation
        Returns:
        true if the signature matches, false otherwise
        Throws:
        SignatureException - if validation fails
      • getDataToSign

        public String getDataToSign​(NotificationRequestItem notificationRequestItem)
                             throws IllegalArgumentException
        Builds the concatenated data string from a NotificationRequestItem to be used in HMAC signature calculation.

        The data string is composed of the following fields, separated by a colon (":"):

        • pspReference
        • originalReference
        • merchantAccountCode
        • merchantReference
        • amount.value
        • amount.currency
        • eventCode
        • success

        If any value is null, it is represented as an empty string in the final payload.

        Parameters:
        notificationRequestItem - the notification request item
        Returns:
        the colon-separated string of fields
        Throws:
        IllegalArgumentException - if the input is null