https://github.com/bwmarrin/go-alone
A simple to use, high-performance, Go (golang) MAC signer.
https://github.com/bwmarrin/go-alone
authentication blake2b hmac hmac-signer itsdangerous jwt mac message-authentication-code signing token token-authetication
Last synced: about 2 months ago
JSON representation
A simple to use, high-performance, Go (golang) MAC signer.
- Host: GitHub
- URL: https://github.com/bwmarrin/go-alone
- Owner: bwmarrin
- License: bsd-2-clause
- Created: 2016-06-14T00:13:09.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-08-06T01:54:24.000Z (over 5 years ago)
- Last Synced: 2025-03-16T08:11:23.384Z (about 2 months ago)
- Topics: authentication, blake2b, hmac, hmac-signer, itsdangerous, jwt, mac, message-authentication-code, signing, token, token-authetication
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 110
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
It's dangerous to go-alone! Take this.
==========================================
[](https://godoc.org/github.com/bwmarrin/go-alone) [](http://goreportcard.com/report/bwmarrin/go-alone) [](https://travis-ci.org/bwmarrin/go-alone) [](https://gocover.io/github.com/bwmarrin/go-alone) [](https://discord.gg/0f1SbxBZjYq9jLBk)
go-alone is a [Go](https://golang.org/) package that provides
* Methods to create and verify [MAC](https://en.wikipedia.org/wiki/Message_authentication_code) signatures of data
* Ability to add timestamps to signed tokens and use custom epoch if needed.
* BLAKE2b signatures and Base58 time encoding provides outstanding performance and security.
* A very simple to use API with good documentation and 100% test coverage.
* Various helper methods for parsing tokens**For more information, please read the [wiki](https://github.com/bwmarrin/go-alone/wiki)**
**For help with this package or general Go discussion, please join the [Discord
Gophers](https://discord.gg/0f1SbxBZjYq9jLBk) chat server.****For a fast and easy to use snowflake ID library, check out [this](https://github.com/bwmarrin/snowflake)**
## Getting Started
This assumes you already have a working Go environment, if not please see
[this page](https://golang.org/doc/install) first.### Installing
```sh
go get github.com/bwmarrin/go-alone
```### Usage
Here's a basic example below. There is also an example program in the [example](https://github.com/bwmarrin/go-alone/tree/master/example)
folder that demonstrates a few more ways of using Go-Alone. You can read the API
documentation on [GoDoc](https://godoc.org/github.com/bwmarrin/go-alone).```go
package mainimport (
"github.com/bwmarrin/go-alone"
)func main() {
// This secret is used as the hash key for the signer.
var secret = []byte("It's a secret to everybody")// This data is what we will be signing below.
var data = []byte("It's dangerous to go alone! Take this.")// Create a new Signer using our secret
s := goalone.New(secret)// Sign and return a token in the form of `data.signature`
token := s.Sign(data)// Unsign the token to verify it - if successful the data portion of the
// token is returned. If unsuccessful then d will be nil, and an error
// is returned.
d, err := s.Unsign(token)
if err != nil {
// signature is not valid. Token was tampered with, forged, or maybe it's
// not even a token at all! Either way, it's not safe to use it.
} else {
// signature is valid, it is safe to use the data
println(string(d))
}
}
```### Performance / Testing
To run the tests and benchmarks, use the following command.
```sh
go test -bench=. -v
```