Search docs

Are you looking for test card numbers?

Would you like to contact support?

Start searching Adyen's documentation...


Signing notifications with HMAC

Protect your server from unauthorised notifications.

Adyen notifications use mutual authentication over SSL in combination with basic authentication that you set up in your Customer Area. To verify that a notification was not modified during transmission, we strongly recommend that you additionally enable Hash-based Message Authentication Code (HMAC) signatures for notifications.

An HMAC signature is calculated using a request's key-value pairs and a secret key, which is known only to you and the Adyen payments platform. By verifying this signature, you'll confirm that the notification was not modified during transmission.

Enable HMAC signatures

To enable HMAC signed notifications, you'll need to generate an HMAC key:

  1. Sign in to your Customer Area, and go to SettingsServer Communication.
  2. For Standard Notification, click Edit & Test.
  3. Under Additional Settings, click  Generate New HMAC key. Copy down your HMAC key. You'll use it to verify HMAC signatures.
  4. Click Save Configuration.

You'll now receive Standard notifications that have been signed with your HMAC key.

If you generate a new HMAC key, it might take some time to propagate this in our infrastructure, so make sure that you can still accept notifications signed with your previous HMAC key for some time.

Verify HMAC signature

You can find a notification's HMAC signature in hmacSignature, contained within its additionalData.

HMAC signatures are calculated using the following key-value pairs:

Key Example
pspReference 7914073381342284
merchantAccountCode TestMerchant
merchantReference TestPayment-1407325143704
amount.value 1130
amount.currency EUR
success true

Signature strings are constructed in the order:


Any fields that are empty will have the value of an empty string. For example, when the originalReference is missing the HMAC signature is constructed with the string: 


To calculate the HMAC signature for a notification:

import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;

public class NotificationHmacExample {
    private static final char SEPARATOR_CHAR = ':';
    public void testNotificationHmac() {
        // Example HEX Key (set in customer portal under: 
        // Settings -> Server Communication -> Standard Notification 
        String keyHex = "009E9E92268087AAD241638D3325201AFC8AAE6F3DCD369B6D32E87129FFAB10";
        // hmacSignature can be found in additionalData.get("hmacSignature") 
        final String hmacSignature = "c5sF0nZAqbyJTzy4OGl4Jij8XyDJwiNpVkU79KT5vTQ=";
        // Example data 
        String pspReference = "7914073251449896";
        String originalReference = "";
        String merchantAccountCode = "TestMerchant";
        String merchantReference = "TestPayment-1407325143704";
        Amount amt = new Amount(1130, "EUR");
        String eventCode = "AUTHORISATION";
        boolean success = true;
        StringBuilder payloadToSign = new StringBuilder();
        if (pspReference != null) {
        if (originalReference != null) {
        if (merchantAccountCode != null) {
        if (merchantReference != null) {
        if (amt == null) {
        } else {
        if (eventCode != null) {
        payloadToSign.append(success ? "true" : "false");
        Base64 base64 = new Base64();
        try {
            // decode HEX Key into bytes 
            byte[] keyBytes = Hex.decodeHex(keyHex.toCharArray());
            // compile the payload to sign 
            String payloadString = payloadToSign.toString();
            // get payload in bytes 
            byte[] payload = payloadString.getBytes("UTF-8");
            // instantiate the MAC object using HMAC / SHA256 
            Mac hmacSha256 = javax.crypto.Mac.getInstance("HmacSHA256");
            // create a key object using the secret key and MAC object 
            SecretKey secretKey = new SecretKeySpec(keyBytes, hmacSha256.getAlgorithm());
            // initialise the MAC object 
            // finalise the MAC operation 
            byte[] signedPayload = hmacSha256.doFinal(payload);
            // encode the signed payload in Base64 
            byte[] encodedSignedPayload = base64.encode(signedPayload);
            System.out.println("original HMAC signature: " + hmacSignature);
            System.out.println("computed HMAC signature: " + new String(encodedSignedPayload, "ASCII"));
            // assert the calculated Base64 encoded HMAC is equal to the received Base64 encoded HMAC 
            assertTrue(Arrays.equals(encodedSignedPayload, hmacSignature.getBytes("UTF-8")));
        } catch (NoSuchAlgorithmException e) {
            // HmacSHA256 should be supported 
        } catch (DecoderException e) {
            // Check key for odd number or characters outside of HEX (base16) 
        } catch (InvalidKeyException e) {
            // The key is invalid 
        } catch (UnsupportedEncodingException e) {
            // UTF-8 should be supported 

If the calculated hmacSignature matches the value you received in the notification, the notification wasn't modified during transmission.

HMAC signature examples

The following are JSON, SOAP, and FORM examples of a notification containing an HMAC signature:

<soap:Envelope xmlns:soap="" xmlns:xsd="" xmlns:xsi="">
      <ns1:sendNotification xmlns:ns1="">
            <live xmlns="">false</live>
            <notificationItems xmlns="">
                        <key xsi:type="xsd:string">hmacSignature</key>
                        <value xsi:type="xsd:string">+JWKfq4ynALK+FFzGgHnp1jSMQJMBJeb87dlph24sXw=</value>
                     <currency xmlns="">EUR</currency>
                     <value xmlns="">1130</value>
                  <originalReference xsi:nil="true" />