I have the following PHP function
public function encodePassword($raw, $salt)
{
return hash_hmac('sha1', $raw . $salt, $this->secret);
}
which I need to translate to Go. I found the following example, but it doesn't involve secret key. https://gobyexample.com/sha1-hashes
How can I create a function in Go, that produces exactly same result as PHP's 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.
Something like this:
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)
}
Like this function:
func decriptSign(message string, key string) string {
h := hmac.New(sha1.New, []byte(key))
h.Write([]byte(message))
return hex.EncodeToString(h.Sum(nil))
}