在進行密碼哈希時,我有以下 node.js 代碼。body.password = covid@19salt = "hello@world"body.passwordhex = crypto.createHmac('sha256', salt).update(body.password).digest('hex');它給出了以下結(jié)果:5fbbff7f6b4db4df6308c6ad7e8fd5afcea513bb70ca12073c7bec618c6b4959現(xiàn)在,我正在嘗試將其轉(zhuǎn)換為它的 go-lang 等效項,我的代碼是body_password := "covid@19"salt := "hello@world"// Create a new HMAC by defining the hash type and the key (as byte array)h := hmac.New(sha256.New, []byte(key))// Write Data to ith.Write([]byte(salt))// Get result and encode as hexadecimal stringhash := hex.EncodeToString(h.Sum(nil))go-lang 的結(jié)果是9b0cb661fcea1bbfe1fa38912e8610f8c0e4707739021988006368c1ba8da8b7我的 go-lang 代碼可能有什么問題?是摘要嗎?
1 回答

縹緲止盈
TA貢獻2041條經(jīng)驗 獲得超4個贊
Javascript 代碼salt用作 HMAC 密鑰并對body_password. 在 Go 中執(zhí)行相同的操作以獲得相同的結(jié)果:
body_password := "covid@19"
salt := "hello@world"
h := hmac.New(sha256.New, []byte(salt))
h.Write([]byte(body_password))
hash := hex.EncodeToString(h.Sum(nil))
在 GoLang PlayGround 上運行程序:https: //play.golang.org/p/GASMDhEhqGi
- 1 回答
- 0 關(guān)注
- 174 瀏覽
添加回答
舉報
0/150
提交
取消