gpt4 book ai didi

go - SHA1 encoding with secret,相当于PHP hash_hmac

转载 作者:数据小太阳 更新时间:2023-10-29 03:32:37 25 4
gpt4 key购买 nike

我有以下 PHP 函数

public function encodePassword($raw, $salt)
{
return hash_hmac('sha1', $raw . $salt, $this->secret);
}

我需要将其翻译成 Go。我找到了以下示例,但它不涉及 key 。 https://gobyexample.com/sha1-hashes

我如何在 Go 中创建一个函数,它产生与 PHP 的 hash_hmac 完全相同的结果?

Update: After Leo's answer, found this resource with hmac examples in many languages: https://github.com/danharper/hmac-examples. Can be useful to somebody.

最佳答案

像这样:

import "crypto/sha1"
import "crypto/hmac"

func hash_hmac_sha1(password, salt, key []byte) []byte {
h := hmac.New(sha1.New, key)
h.Write(password)
h.Write(salt)
return h.Sum(nil)
}

关于go - SHA1 encoding with secret,相当于PHP hash_hmac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51805913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com