25 lines
363 B
Go
25 lines
363 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"golang.org/x/crypto/blake2b"
|
||
|
)
|
||
|
|
||
|
func GenerateToken(pkey []byte, id int, a... []byte) ([]byte, error) {
|
||
|
h, err := blake2b.New(blake2b.Size, nil)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
h.Write(pkey)
|
||
|
h.Write([]byte(fmt.Sprintf(":%d", id)))
|
||
|
|
||
|
for _, v := range a {
|
||
|
h.Write([]byte(":"))
|
||
|
h.Write(v)
|
||
|
}
|
||
|
|
||
|
return h.Sum(nil), nil
|
||
|
}
|