blob: e249d38449a39c91308d15d6b722ad652607f0ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package crypto
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"shrine/config"
)
func GenerateToken() (string, error) {
bytes := make([]byte, 32)
_, err := rand.Read(bytes)
if err != nil {
return "", err
}
return hex.EncodeToString(bytes), nil
}
func HashToken(rawToken string) string {
mac := hmac.New(sha256.New, []byte(config.Server.Secret))
mac.Write([]byte(rawToken))
return hex.EncodeToString(mac.Sum(nil))
}
|