The hmacvalidator
package provides a simple yet powerful HMAC validator in Go.
It supports both SHA256 and SHA1 hashing algorithms for HMAC validation.
- Supports SHA256 and SHA1 HMAC validation.
- Fluent API for HMAC validation.
- Utility methods for both valid and invalid HMAC checks.
go get github.com/xorima/hmacvalidator
Create a new HMAC validator by specifying the hash type and secret.
import "github.com/xorima/hmacvalidator"
validator := hmacvalidator.NewHMACValidator(hmacvalidator.HashSha256, "your-secret-here")
Use the IsValid method to validate the HMAC signature of a given body.
body := []byte("your-message-body-here")
signature := "sha256=your-signature-here"
if validator.IsValid(body, signature) {
fmt.Println("Valid signature!")
} else {
fmt.Println("Invalid signature!")
}
You can also use the IsInvalid
method as a convenience for !IsValid
.
This project adheres to Semantic Versioning (SemVer). For the versions available, see the tags on this repository.
Clone the repository:
git clone https://github.com/xorima/hmacvalidator.git
Navigate to the project directory:
cd hmacvalidator
Use the provided Makefile for common development tasks:
make lint
: Run golangci-lint on the project.make test
: Run tests for the project.
This project uses golangci-lint
for linting.
Ensure you have it installed or use the provided Makefile to lint the project.
Run the tests using the Makefile:
make test