2 Star 0 Fork 0

江苏艾雨文承养老机器人有限公司/aywc_judge

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MqttSign.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
dtal 提交于 2021-06-02 09:26 +08:00 . init
package lib
import (
"bytes"
"crypto/hmac"
"crypto/sha1"
"fmt"
)
type AuthInfo struct {
Password, Username, MqttClientId string
}
func Calculate_sign(clientId, productKey, deviceName, deviceSecret, timeStamp string) AuthInfo {
var raw_passwd bytes.Buffer
raw_passwd.WriteString("clientId" + clientId)
raw_passwd.WriteString("deviceName")
raw_passwd.WriteString(deviceName)
raw_passwd.WriteString("productKey")
raw_passwd.WriteString(productKey)
raw_passwd.WriteString("timestamp")
raw_passwd.WriteString(timeStamp)
fmt.Println(raw_passwd.String())
// hmac, use sha1
mac := hmac.New(sha1.New, []byte(deviceSecret))
mac.Write([]byte(raw_passwd.String()))
password := fmt.Sprintf("%02x", mac.Sum(nil))
fmt.Println(password)
username := deviceName + "&" + productKey
var MQTTClientId bytes.Buffer
MQTTClientId.WriteString(clientId)
// hmac, use sha1; securemode=2 means TLS connection
MQTTClientId.WriteString("|securemode=2,_v=paho-go-1.0.0,signmethod=hmacsha1,timestamp=")
MQTTClientId.WriteString(timeStamp)
MQTTClientId.WriteString("|")
auth := AuthInfo{Password: password, Username: username, MqttClientId: MQTTClientId.String()}
return auth
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/aywc_1/aywc_judge.git
git@gitee.com:aywc_1/aywc_judge.git
aywc_1
aywc_judge
aywc_judge
v0.6.3

搜索帮助