API Security
Last updated
Was this helpful?
Last updated
Was this helpful?
In cryptography, an HMAC (sometimes extended as either keyed-hash message authentication code or hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key.
HMAC protocol is widely used in the industry and is one of the key protocols for the Web Payments standard, which issues.
API key creation happens upon customer creation. Our system ensures API security using API keys and HMAC secrets. API keys are random strings that are almost impossible to brute force. However, these keys need an additional layer of security. The system transmits API keys to the user with an HTTPS request, and the system has to display these values on the screen. This kind of communication makes them vulnerable. With HMAC, the system uses a non-exposable entity when intercommunicating with the customer.
Hmac secret should be stored securely, preferably in an encrypted database. Before communicating with our system, the calling end must enable HMAC security by submitting the HMAC secret. Otherwise, the system refuses the request with a response of HTTP 400 (Bad Request). Only the communicating ends know this secret. You can use UUID version 4 while generating a safe HMAC secret.
It is advisable to update this secret periodically when there is no ongoing traffic. This step will help ensure maximum protection and minimize the likelihood of unauthorized access or security breaches.
After enabling HMAC, the customers must sign their POST requests with the HMAC, Sha-2, 512-bit hash algorithm, and the result must be base64 encoded. The customers must pass this signed base64 encoded hash with the header x-payload-hash to our API endpoints for each POST request.
Here is our TypeScript example for opening a deposit tracking session. In this example, you can learn how to calculate an HMAC and pass this hash for your post requests.
You should first JSON.stringify the body and then calculate the x-payload-hash using this stringified body. After that, pass this hash onto your x-payload-hash header and the stringified body (which you have used to calculate HMAC) for your POST requests.
The result of the HMAC calculation should be base 64 encoded.