SHA1 encoding with secret, equivalent to PHP hash_hmac

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



SHA1 encoding with secret, equivalent to PHP hash_hmac



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.





Did you already try the hmac package?
– apxp
Aug 12 at 5:28





For sha1 encoding: hmac.New(sha1.New, key)
– apxp
Aug 12 at 5:29


hmac.New(sha1.New, key)




1 Answer
1



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)





Thanks Leo, this is what I was looking for.
– yagger
Aug 12 at 14:04






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS