> ## Documentation Index
> Fetch the complete documentation index at: https://developers.docistra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Verify signatures

> Make sure a webhook really came from Docistra.

Every webhook has an `X-Docistra-Signature` header:

```
X-Docistra-Signature: t=1764583200,v1=5f2b0c9a...
```

* `t` is when it was signed (Unix seconds).
* `v1` is the hex HMAC-SHA256 of `"<t>.<raw request body>"`, keyed with your endpoint's signing secret.

To verify:

1. Read the **raw** body, before any JSON parsing.
2. Compute `HMAC-SHA256(secret, t + "." + rawBody)` as hex.
3. Compare it with `v1` in constant time.
4. Reject it if `t` is more than 5 minutes away from now (replays).

```js Node.js theme={null}
import crypto from "node:crypto";

export function verifyDocistra(rawBody, header, secret, toleranceSec = 300) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSec) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1 ?? "");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}
```

```python Python theme={null}
import hmac, hashlib, time

def verify_docistra(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t = int(parts.get("t", "0"))
    if not t or abs(time.time() - t) > tolerance:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))
```

```php PHP theme={null}
function verify_docistra(string $rawBody, string $header, string $secret, int $tolerance = 300): bool {
    parse_str(str_replace(',', '&', $header), $parts);
    $t = (int)($parts['t'] ?? 0);
    if (!$t || abs(time() - $t) > $tolerance) return false;
    $expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);
    return hash_equals($expected, $parts['v1'] ?? '');
}
```

```csharp C# theme={null}
using System.Security.Cryptography;
using System.Text;

static bool VerifyDocistra(string rawBody, string header, string secret, int toleranceSec = 300) {
    var parts = header.Split(',').Select(p => p.Split('=', 2)).ToDictionary(p => p[0], p => p[1]);
    var t = long.Parse(parts.GetValueOrDefault("t", "0"));
    if (t == 0 || Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - t) > toleranceSec) return false;
    using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
    var expected = Convert.ToHexString(hmac.ComputeHash(Encoding.UTF8.GetBytes($"{t}.{rawBody}"))).ToLowerInvariant();
    return CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(parts.GetValueOrDefault("v1", "")));
}
```

## Rotating the secret

Press **New secret** under the key in Docistra. The old secret stops at once, so update your system right after.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.