Golang code is as below
func GenerateClientToken(secret, user, timestamp, info string) string {
token := hmac.New(sha256.New, []byte(secret))
token.Write([]byte(user))
token.Write([]byte(timestamp))
token.Write([]byte(info))
return hex.EncodeToString(token.Sum(nil))
}
How can I convert from this to reactjs code. I am trying like this
import CryptoJS from 'crypto-js'
generateClientToken(secret, user, timestamp, info) {
var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secret);
hmac.update(user);
hmac.update(timestamp);
hmac.update(info);
var hash = hmac.finalize();
console.log("hmac: ", hash.toString(CryptoJS.enc.Base64))
console.log("hmac: ", hash.toString(CryptoJS.enc.Hex))
}
but result is not same with golang result. What am I wrong? and How will I do?