golang计算sha256

0
1297

golang要怎么使用计算sha256呢?直接上代码

mac := hmac.New(sha256.New, []byte("你的秘钥"))
mac.Write([]byte("你需要计算签名的文字"))
hex.EncodeToString(mac.Sum(nil))//这个就是你计算出来sha256的签名了

要是只计算字符串的sha256就是这个样子的


h := sha256.New()
h.Write([]byte("hello world\n"))
hex.EncodeToString(h.Sum(nil))

这样就可以了

hex.EncodeToString()很重要,要不会乱码。

回复

请输入你的评论!
请在这里输入您的名字