https://github.com/pascalallen/hmac
hmac is a Go module that offers services for HTTP HMAC authentication.
https://github.com/pascalallen/hmac
go golang hmac hmac-authentication
Last synced: over 1 year ago
JSON representation
hmac is a Go module that offers services for HTTP HMAC authentication.
- Host: GitHub
- URL: https://github.com/pascalallen/hmac
- Owner: pascalallen
- License: mit
- Created: 2023-02-01T15:38:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-20T00:31:03.000Z (over 3 years ago)
- Last Synced: 2025-01-06T05:41:49.250Z (over 1 year ago)
- Topics: go, golang, hmac, hmac-authentication
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hmac
[](https://pkg.go.dev/github.com/pascalallen/hmac)

[](https://goreportcard.com/report/github.com/pascalallen/hmac)



hmac is a Go module that offers services for HTTP HMAC authentication.
## Installation
Use the Go CLI tool [go](https://go.dev/dl/) to install hmac.
```bash
go get github.com/pascalallen/hmac
```
## Usage
```go
...
import "github.com/pascalallen/hmac"
...
publicKey := hmac.GenerateSecureRandom(16)
privateKey := hmac.GenerateSecureRandom(16)
var timeTolerance int64 = 300
request, _ := http.NewRequest(
http.MethodPost,
"http://localhost:8080?abc=xyz",
bytes.NewReader([]byte(`{"foo": "bar"}`)),
)
// create request service and sign request
requestService, _ := hmac.NewRequestService(publicKey, privateKey)
signedRequest := requestService.SignRequest(request)
// create authenticator and validate signed request
authenticator, _ := hmac.NewAuthenticator(publicKey, privateKey, timeTolerance)
isValid := authenticator.Validate(*signedRequest)
...
```
## Testing
Run tests and create coverage profile:
```bash
go test -covermode=count -coverprofile=coverage.out
```
View test coverage profile:
```bash
go tool cover -html=coverage.out
```
## Contributing
Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.
Please make sure to update tests as appropriate.
## License
[MIT](LICENSE)