golang
func hmacSha256(src string, secret string) string {
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(src))
shaStr:= fmt.Sprintf("%x",h.Sum(nil))
//shaStr:=hex.EncodeToString(h.Sum(nil))
return base64.StdEncoding.EncodeToString([]byte(shaStr))
}
fmt.Println(hmacSha256("hello", "duzhenxun"))
PHP
echo base64_encode(hash_hmac('sha256','hello','duzhenxun'));
本文对比展示了如何使用Go语言和PHP实现HMAC-SHA256算法,通过具体的代码示例,详细解释了两种语言中该算法的使用方法及其实现过程。
1377

被折叠的 条评论
为什么被折叠?



