pack("H*", $string) 转化成这样:
//16进制字符串转[]byte func HexToByte(hex string) []byte { length := len(hex) / 2 slice := make([]byte, length) rs := []rune(hex) for i := 0; i < length; i++ { s := string(rs[i*2 : i*2+2]) value, _ := strconv.ParseInt(s, 16, 10) slice[i] = byte(value & 0xFF) } return slice }
oneNet平台的数据校验:
func CheckSignature(nonce, msg, sign string ) string { new_sig := MD5_encrypt(token + nonce + msg) fmt.Println(strings.ToUpper(new_sig)) // upper upper := strings.ToUpper(new_sig) new_sig = base64.StdEncoding.EncodeToString(HexToByte(upper)) fmt.Println("byte", []byte(strings.ToUpper(new_sig))); fmt.Println("new_sig", new_sig) fmt.Println("sign", sign) if new_sig == sign { return msg } else { return "" } } //16进制字符串转[]byte func HexToByte(hex string) []byte { length := len(hex) / 2 slice := make([]byte, length) rs := []rune(hex) for i := 0; i < length; i++ { s := string(rs[i*2 : i*2+2]) value, _ := strconv.ParseInt(s, 16, 10) slice[i] = byte(value & 0xFF) } return slice }