Bank API Integration Checklist: AES-256-GCM Encryption and HMAC Signing
Checklist for bank and AEPS API integrations with AES-256-GCM payloads and HMAC-SHA256 signing: keys, IVs, signatures, UAT logs, retries and status enquiry.
Why bank integrations are different
Bank APIs rarely accept plain JSON. Requests are usually encrypted, signed and tied to a timestamp, and responses come back encrypted too. A single wrong byte gives you a generic error with no hint about what went wrong.
The documentation is often a PDF with one sample request, a sample key and a table of error codes. Your job is to reproduce that sample exactly, byte for byte, before you send a single real request. This checklist follows the order I work through on integrations such as the bank batch-payment integration, where beneficiary requests and enquiries were encrypted with AES-256-GCM and signed with HMAC-SHA256.
0. Collect everything before writing code
Ask the bank for the UAT base URL, the encryption key and HMAC secret (they are often different values), any client ID or API key headers, the IP addresses they need to whitelist, and at least one complete worked example: plaintext, encrypted payload, signature and expected response. A worked example turns guesswork into a simple comparison, so it is worth waiting a day for.
1. Confirm the exact key format
Check whether the key is shared as raw bytes, hex or Base64, and decode it to exactly 32 bytes for AES-256. Many failures start with a key that was used as a text string instead of decoded bytes.
A quick sanity check: a 32-byte key is 64 characters in hex and 44 characters in Base64 (ending in =). If your key is 32 characters long, it may be meant as plain text bytes, or it may be half a hex key. Ask instead of guessing, and print the decoded length in your test script.
2. Get the IV and tag layout right
AES-GCM needs an IV (often 12 bytes) and produces an authentication tag (usually 16 bytes). Confirm with the bank how they expect these packed: IV first, tag at the end, everything Base64-encoded together, or sent as separate fields.
Generate a fresh random IV for every request. Reusing an IV with the same key breaks the security of GCM, and some banks reject repeated values outright. Also check whether the bank uses additional authenticated data (AAD). If they do and you leave it out, decryption fails on their side with an error that looks exactly like a wrong key.
In PHP, openssl_encrypt with aes-256-gcm and the OPENSSL_RAW_DATA flag returns raw ciphertext and fills the tag by reference. In Node.js, crypto.createCipheriv works the same way, and you read the tag with getAuthTag() after calling final(). In both languages, concatenate raw bytes first and Base64-encode once at the end; encoding each part separately and joining the strings is a common mistake.
3. Sign exactly what the bank signs
HMAC-SHA256 has to be calculated over the exact string the bank expects: sometimes the encrypted payload, sometimes the plain JSON, sometimes fields joined in a fixed order. Match whitespace, field order and encoding character for character.
Watch the JSON serializer. PHP's json_encode escapes forward slashes and non-ASCII characters unless you pass JSON_UNESCAPED_SLASHES and JSON_UNESCAPED_UNICODE, and a pretty-printed body will never match a compact one. Serialize the body once, sign that exact string, and send that same string. Also confirm the output format of the signature: lowercase hex and Base64 are both common, and they are not interchangeable.
4. Timestamps, request IDs and headers
Most bank APIs want a timestamp in a specific format and time zone, and reject requests outside a short window. Keep the server clock synced, and format the time exactly as documented. Each request also usually needs a unique reference ID. Store it before you send the request, so you can enquire about it later and so a retry never creates a duplicate payout.
5. Decrypt and verify responses
Responses usually follow the same layout as requests. Verify the signature or tag first, then decrypt, then parse. If a response cannot be verified, treat the transaction as unknown, not as failed, and let the status enquiry job resolve it. Map the bank's error codes to clear internal states (success, failed, pending) instead of passing raw codes to your dashboard.
6. Log safely in UAT
Log the plaintext request, the encrypted payload, the signature and the raw response in UAT so you can compare them with the bank's sample values. Remove sensitive logs before production.
In production, log the reference ID, HTTP status, bank response code and timing, but never keys, full account numbers or decrypted personal data. Keep keys and secrets in environment variables or a secrets store, not in the repository, and plan for key rotation: the bank may issue new keys after UAT or on a schedule.
7. Timeouts and retries
A timeout does not mean the bank did not process the request. Never blindly resend a payout after a timeout. Mark the record as pending, then check its real status through the enquiry API. Retries are safe only when the bank confirms the earlier request was not received, or when the API is clearly idempotent on your reference ID.
8. Plan for status enquiry
Payouts and beneficiary requests are not always final immediately. Build an enquiry job that checks pending records and updates their status, so your records always match the bank's.
Run it on a schedule with back-off, stop after a defined number of attempts, and flag anything still pending for a person to review. A daily report that compares your records with the bank's statement catches the rare mismatch before a customer does. The same pattern applies to wallets and settlements on an AEPS platform.
9. Go-live checklist
Before switching to production, confirm that: the production server IP is whitelisted; production keys are loaded from the environment and the UAT keys are removed; sensitive debug logs are off; every request carries a unique reference ID; timeouts move records to pending instead of failed; the enquiry job is running; and someone receives an alert when it finds stuck records.
Working on a bank or AEPS integration that keeps returning errors? I have debugged these in UAT and can help you get to production. See my bank API integration service for what is included.
Case studies using this approach
Bank batch-payment integration
Beneficiary request and enquiry flows with AES-256-GCM encryption and HMAC-SHA256 signing, from UAT to go-live.
Read case study →FintechAEPS & payments dashboard
Platform-owner dashboard and backend for a payments product, containerised and deployed with Coolify.
Read case study →Hire me for this
Fintech & bank API integration
Bank and payment APIs are strict: encrypted payloads, signed requests, UAT certification and no room for silent failures. This is…
Learn more →ServiceNode.js, PHP & API development
The backend is where business rules live. I design MySQL schemas and build REST APIs in Node.js/Express or PHP that web and…
Learn more →