https://github.com/vicanso/keygrip
Key signing and verification for rotated credentials
https://github.com/vicanso/keygrip
go keygrip
Last synced: 8 months ago
JSON representation
Key signing and verification for rotated credentials
- Host: GitHub
- URL: https://github.com/vicanso/keygrip
- Owner: vicanso
- License: mit
- Created: 2018-08-01T13:56:03.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-19T10:55:47.000Z (over 2 years ago)
- Last Synced: 2024-12-27T19:44:47.432Z (10 months ago)
- Topics: go, keygrip
- Language: Go
- Size: 21.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# keygrip
[](https://github.com/vicanso/keygrip/actions)
Keygrip is a module for signing and verifying data (such as cookies or URLs) through a rotating credential system, in which new server keys can be added and old ones removed regularly, without invalidating client credentials. It derives from [crypto-utils/keygrip](https://github.com/crypto-utils/keygrip).
## API
#### kg := keygrip.New(keyList []string)
```go
kg := keygrip.New([]string{
"key1",
"key2",
})
```#### Sign(data []byte)
Get the base64 digest(RawURLEncoding) on the first key in the keylist.
```go
kg := keygrip.New([]string{
"key1",
"key2",
})
str := kg.Sign([]byte("tree.xie"))
// VOauNTAF3i24kD9EN5foGvhXNnI
fmt.Println(string(str))
```#### Verify(data, digest []byte)
This loops through all of the keys currently in the keylist until the digest of the current key matches the given digest. Otherwise it will return false.
```go
kg := keygrip.New([]string{
"key1",
"key2",
})
fmt.Println(kg.Verify([]byte("tree.xie"), []byte( "VOauNTAF3i24kD9EN5foGvhXNnI")))
```#### Index(data, digest []byte)
This loops through all of the keys currently in the keylist until the digest of the current key matches the given digest, at which point the current index is returned. If no key is matched, -1 is returned.
```go
kg := keygrip.New([]string{
"key1",
"key2",
})
fmt.Println(kg.Index([]byte("tree.xie"), []byte("VOauNTAF3i24kD9EN5foGvhXNnI")))
```#### AddKey(key string)
Add key to the front of key list
```go
kg := keygrip.New([]string{
"key1",
"key2",
})
kg.Add("key3")
```#### RemoveKey(key string)
Remove key from key list
```go
kg := keygrip.New([]string{
"key1",
"key2",
})
kg.Remove("key1")
```#### Keys()
Get the key list
```go
kg := keygrip.New([]string{
"key1",
"key2",
})
kg.Keys()
```## test
make test-cover
### bench
make bench