> For the complete documentation index, see [llms.txt](https://docs.coda.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coda.co/codapay/direct-api-integration/direct-api-integration-for-cards/getting-started/how-to-generate-the-x-signature.md).

# How to generate the x-signature

For every charge request notification, the Coda system will carry out a verification process to ensure its integrity. Coda will compare the ***x-signature*** header in the request with the signature of the request body.\
\
If the signatures do not match, our system will reject the request and return error.\
\
This process is to ensure the integrity and security of our charge requests, reducing the risk of any payload being tampered.<br>

*Generating the signature*

The code snippet below is a sample code for generating signatures. Steps are also explained further below.

```java
public String generateSignature(@Nonull String requestTime, @Nonull String
requestBody, @Nonull String signingSecret) {
// Construct signature message
Coda Payments Pte. Ltd. Confidential
20
String message = String.format("%s.%s"
, requestTime, requestBody);
// using commons-codec:commons-codec:1.16.0 library
return new HmacUtils("HmacSHA512"
, signingSecret).hmacHex(message);
}
```

*Steps:*

1. Append the values listed below as a string as follows: *"{requestTime}.{requestBody}".*\
   *Example:*

```java
RequestTime = 1700486578888
RequestBody = {"type":"charge.status.succeeded","data":{"id":"evt_sg18c678ba5af0019"}}
String message =
"1700486578888.{"type":"charge.status.succeeded","data":{"id":"evt_sg18c678ba5af0019"}}"
```

2. Calculate the HMAC-SHA512 hash of the string using your signing secret as the key. The signing secret is a pre-shared key configured for your webhook endpoint. The HMAC-SHA512 algorithm will return a byte array value.

   *Example:*

```java
SigningSecret = "BbCVjTu59yVUMMon8mgN9C37piCGfijN"
```

3. Convert the byte array value to a hexadecimal string. The result will be like:

   "a0c2d905877e9282a3954743f918f98f991c144020c535458c84767b6e146cf8cad4433accc2047258f6d5c4be07264596cfc58cfeea9e8551090f26e828e6bd"

*Verifying the Signature*

1. Extract the X-Request-Time and X-Signature headers from the webhook request
2. Get the raw request body as a string (before any parsing)
3. Generate the expected signature following Steps 1-3 above
4. Compare the generated signature with the X-Signature header value using a constant-time comparison
5. Verify that the X-Request-Time is within an acceptable time window (e.g., within last 5 minutes) to prevent replay attacks


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coda.co/codapay/direct-api-integration/direct-api-integration-for-cards/getting-started/how-to-generate-the-x-signature.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
