|
@ -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 |
|
|
|
|
|
} |