HMACSHA256 哈希是否可以从一台服务器转移到另一台服务器?
如果我在密码编码方案中使用 HMACSHA256.ComputeHash
并在一台服务器上生成密码哈希值,然后需要迁移到另一台服务器,我的哈希值仍然会编码相同吗?我记得看到过有关加密操作中涉及 machineKey
设置的内容,但我并不完全熟悉。
If I use HMACSHA256.ComputeHash
in my password encoding scheme and generate password hashes on one server then later need to migrate to a different server, will my hashes still encode the same? I recall seeing something about machineKey
settings being involved in cryptography operations, but I'm not entirely familiar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它们是否仍然会进行相同的编码取决于您如何创建 HMACSHA256 对象。它将使用您实例化它所用的任何密钥来执行哈希,或者,如果您未指定密钥,它将生成一个随机密钥。只要你向它传递相同的密钥,它就会生成相同的哈希值。
Whether or not they will still encode the same depends on how you create the HMACSHA256 object. It will use whatever key you instantiate it with to do the hashes or, if you don't specify a key, it will generate a random key. As long as you pass it the same key, it will generate the same hashes.
HMAC 根据秘密和您想要验证的数据计算哈希值。为了让两台服务器计算相同的 HMAC,它们必须共享该秘密,这可能使其不再那么秘密。为了也能够验证旧密码,需要修复该秘密,或者以某种方式沿着存储的密码进行引用(如果它可以更改),使其实际上成为一种盐。
在密码存储设置中使用 HMAC 非常奇怪,它不是一个正确的密码派生函数(速度太快,内存不够密集),并且秘密不会带来太多价值(如果有的话),因为它必须被修复(与正确的 HMAC 使用不同)其中秘密由通信双方在会话中达成一致,但之后就被遗忘了)。
HMAC computes a hash from a secret and the data you want to authenticate. In order for two servers to compute the same HMAC they'll have to share the secret, which possibly makes it not that secret. In order too be able to verify old password the secret will need either to be fixed or to be somehow referenced along the stored password if it can changes, making it practically a salt.
Using HMAC in a password storage setting is pretty odd, it's not a proper password derivation function (way too fast, not memory intensive enough) and the secret don't bring much value if any, seeing it must be fixed (unlike proper HMAC usage where the secret is agreed upon by the communicating parties for a session and forgotten about after).