node.js - 隐蔽 Node.js 加密 HMAC 到 Go-lang HMAC 加密
问题描述
在进行密码哈希时,我有以下 node.js 代码。
body.password = covid@19
salt = "hello@world"
body.passwordhex = crypto.createHmac('sha256', salt).update(body.password).digest('hex');
它给出了以下结果:
5fbbff7f6b4db4df6308c6ad7e8fd5afcea513bb70ca12073c7bec618c6b4959
现在,我正在尝试将其转换为它的 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 it
h.Write([]byte(salt))
// Get result and encode as hexadecimal string
hash := hex.EncodeToString(h.Sum(nil))
go-lang 的结果是
9b0cb661fcea1bbfe1fa38912e8610f8c0e4707739021988006368c1ba8da8b7
我的 go-lang 代码可能有什么问题?是摘要吗?
解决方案
Javascript 代码salt
用作 HMAC 密钥并对body_password
. 在 Go 中执行相同的操作以获得相同的结果:
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
推荐阅读
- mysql - MySQL在过程中的if语句中选择
- c - 如果 scanf 类型错误,我应该如何打破循环?(C)
- c# - “xxx' 由于其保护级别而无法访问” 一切都是公开的(我认为)
- python - 获取点赞数、转发数和评论数最多的推文
- reactjs - .NET webapi 端点在 Postman 中工作,但 Chrome 提供 net::ERR_FAILED
- javascript - 为什么不能直接更新对象中嵌套属性的值?
- javascript - 当搜索/过滤列表组中的字段为空白时隐藏结果
- python-3.x - 将最新文件从 S3 存储桶导入 Pandas 数据框
- ios - 如何在其他地方使用条形码扫描仪的结果?
- javascript - 如何在 JavaScript 中使用选中的单选按钮值