Documentation
¶
Overview ¶
Package security provides cryptographic utilities for webhook signing and verification.
Index ¶
- Constants
- func AddSignatureHeaders(headers http.Header, secret string, payload []byte)
- func AddSignatureToMap(headers map[string]string, secret string, payload []byte)
- func ExtractSignature(headers http.Header) (string, bool)
- func GenerateSecret(length int) (string, error)
- func SignPayload(secret string, payload []byte) string
- func SignPayloadWithTimestamp(secret string, timestamp int64, payload []byte) string
- func VerifySignature(secret string, payload []byte, signature string) bool
- func VerifySignatureWithTimestamp(secret string, timestamp int64, payload []byte, signature string) bool
- type Signer
Constants ¶
const ( // SignatureHeader is the HTTP header name for the webhook signature. SignatureHeader = "X-Webhook-Signature" // SignatureAlgorithmHeader is the HTTP header name for the signature algorithm. SignatureAlgorithmHeader = "X-Webhook-Signature-Algorithm" // TimestampHeader is the HTTP header name for the webhook timestamp. TimestampHeader = "X-Webhook-Timestamp" // DefaultAlgorithm is the default HMAC algorithm used for signing. DefaultAlgorithm = "sha256" )
Variables ¶
This section is empty.
Functions ¶
func AddSignatureHeaders ¶
AddSignatureHeaders adds signature headers to an HTTP request.
func AddSignatureToMap ¶
AddSignatureToMap adds signature to a map of headers.
func ExtractSignature ¶
ExtractSignature extracts the signature from HTTP headers. Supports various common header formats.
func GenerateSecret ¶
GenerateSecret generates a cryptographically secure secret for webhook signing. The secret will be a hex-encoded string of the specified length in bytes.
func SignPayload ¶
SignPayload generates an HMAC-SHA256 signature for the given payload.
func SignPayloadWithTimestamp ¶
SignPayloadWithTimestamp generates a signature including a timestamp for replay protection.
func VerifySignature ¶
VerifySignature verifies that the provided signature matches the expected signature. Uses constant-time comparison to prevent timing attacks.