diff options
Diffstat (limited to 'shrine/utils/crypto/token.go')
| -rw-r--r-- | shrine/utils/crypto/token.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/shrine/utils/crypto/token.go b/shrine/utils/crypto/token.go new file mode 100644 index 0000000..e249d38 --- /dev/null +++ b/shrine/utils/crypto/token.go @@ -0,0 +1,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)) +}
\ No newline at end of file |
