Principal
How to verify data integrity in a webhook? How to protect data at the transport level?
sobes.tech AI
Answer from AI
To verify data integrity in a webhook, digital signatures or HMAC (Hash-based Message Authentication Code) are usually used. The sender computes a hash of the message with a secret key and sends it in the header. The receiver recomputes the HMAC and compares it with the received value — if they match, the data has not been altered.
To protect data at the transport level, the HTTPS (TLS) protocol is used, which provides channel encryption and prevents data interception or tampering.
Example of HMAC verification on the receiver's side (in Python):
import hmac
import hashlib
def verify_signature(secret, payload, signature):
computed = hmac.new(secret.encode(), payload, hashlib.sha256).hexdigest()
return hmac.compare_digest(computed, signature)
Thus, integrity and security are ensured by a combination of cryptographic verification and a secure transmission channel.