Browse Source

增加sign

master v0.0.4
guzeng 3 years ago
parent
commit
e119ffb2ee
1 changed files with 37 additions and 0 deletions
  1. +37
    -0
      sign.go

+ 37
- 0
sign.go View File

@ -0,0 +1,37 @@
package taskrpc
import (
"crypto/md5"
"encoding/hex"
"strings"
)
/**
* 签名
*/
func Sign(data string, salt string) string {
var build strings.Builder
build.WriteString(data)
build.WriteString(salt)
build.WriteString("ta334signsk98")
data_str := build.String()
h := md5.New()
h.Write([]byte(data_str)) // 需要加密的字符串
return hex.EncodeToString(h.Sum(nil)) // 输出加密结果
}
/**
* 验证签名
*/
func CheckSign(sign_str, data, salt string) bool {
sign := Sign(data, salt)
if strings.Compare(sign_str, sign) > -1 {
return true
}
return false
}

Loading…
Cancel
Save