fix: fix srun md5 logic

reference to #31
This commit is contained in:
Mmx233
2024-03-23 16:51:53 +08:00
parent 575aad904a
commit 99b43d403c
2 changed files with 13 additions and 6 deletions

View File

@@ -1,17 +1,21 @@
package srun
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
)
// Md5 编码
func Md5(content string) string {
w := md5.New()
_, _ = io.WriteString(w, content)
return fmt.Sprintf("%x", w.Sum(nil))
func Md5(token, password string) (string, error) {
mac := hmac.New(md5.New, []byte(token))
_, err := mac.Write([]byte(password))
if err != nil {
return "", err
}
return hex.EncodeToString(mac.Sum(nil)), nil
}
// Sha1 编码