diff options
Diffstat (limited to 'db/utils.go')
-rw-r--r-- | db/utils.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/db/utils.go b/db/utils.go new file mode 100644 index 0000000..0b0f1cb --- /dev/null +++ b/db/utils.go @@ -0,0 +1,24 @@ +package db + +import ( + "encoding/base64" + "lukechampine.com/blake3" + "math/rand" +) + +func ToBlake3(pass string) string { + hash := blake3.Sum512([]byte(pass)) + hash64b := base64.StdEncoding.EncodeToString(hash[:]) + + return "blake3-" + hash64b +} + +func GenRandomString(n int) (string, error) { + b := make([]byte, n) + _, err := rand.Read(b) + if err != nil { + return "", err + } + + return base64.URLEncoding.EncodeToString(b)[:n], nil +} |