This repository has been archived on 2024-03-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
adlin/token-validator/token.go
2021-02-13 21:23:18 +01:00

22 lines
332 B
Go

package main
import (
"crypto/sha512"
"fmt"
)
func GenerateToken(pkey []byte, id int, a ...[]byte) ([]byte, error) {
h := sha512.New()
h.Write([]byte(fmt.Sprintf("%x", pkey)))
if id != 0 {
h.Write([]byte(fmt.Sprintf(":%d", id)))
}
for _, v := range a {
h.Write([]byte(":"))
h.Write(v)
}
return h.Sum(nil), nil
}