mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
25 lines
410 B
Go
25 lines
410 B
Go
package common
|
|
|
|
import (
|
|
"crypto/sha512"
|
|
"encoding/base64"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func HashPassword(pwd string) []byte {
|
|
h := sha512.New()
|
|
h.Write([]byte(pwd))
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
func decodeJWTKey(key string) []byte {
|
|
if key == "" {
|
|
return nil
|
|
}
|
|
bytes, err := base64.StdEncoding.DecodeString(key)
|
|
if err != nil {
|
|
log.Panic().Err(err).Msg("failed to decode jwt key")
|
|
}
|
|
return bytes
|
|
}
|