简体   繁体   English

加密与哈希密码

[英]Encryption vs Hashing Passwords

Suppose I want develop a authetication/user system, and I'd like to be able to recover original users passwords if I need, what are the disvantages to encrypt password vs hashing from the security point of view? 假设我要开发一个身份验证/用户系统,并且如果需要的话,我希望能够恢复原始用户的密码,从安全角度来看,加密密码与散列相比有什么缺点?

Of course the application will use just the public key, and the authetication will be executed just comparing the encrypted strings with the public key. 当然,应用程序将仅使用公共密钥,并且只需将加密的字符串与公共密钥进行比较即可执行认证。

The private key can be used in two way: 私钥可以通过两种方式使用:

  1. I keep the private key on my offline devices for special manual password recovery operation. 我将私钥保留在脱机设备上,以进行特殊的手动密码恢复操作。
  2. The private key is in the application but encrypted with a password. 私钥在应用程序中,但已用密码加密。

Considering nobody (except me) can access the private key, what are the security weakness of these implementation choices rather than hashing password? 考虑到除了我以外,没有人可以访问私钥,这些实现选择而不是哈希密码的安全性弱点是什么?

About the second option, potentially a hacker can hack the application server and wait I insert the password to decrypt the private key, but I think in this case the hacker can already do many more bad actions than to wait the private key decryption (as wait just user send their password when login and others...) 关于第二种选择,潜在的黑客可能会入侵应用程序服务器并等待我插入密码来解密私钥,但是我认为在这种情况下,黑客已经可以比等待私钥解密(如只是用户在登录时发送密码,其他用户...)

Thanks 谢谢

EDIT: What I would mainly understand, is if using encryption is as safe as using hashing (of course supposing the cracker can't get private key). 编辑:我主要要理解的是,使用加密是否像使用哈希一样安全(当然,假设破解者无法获取私钥)。

If your question is whether proper hash algorithms have flaws, and proper encryption schemes are correct then yes - both of them are correct for the intended usage. 如果您的问题是适当的哈希算法是否存在缺陷,并且正确的加密方案正确,那么可以-两者对于预期的用途都是正确的。

This means that for instance for hashes there are no collisions and no reversibility. 这意味着,例如,对于哈希,没有冲突,也没有可逆性。 For encryption it would mean that one cannot decrypt within reasonable time. 对于加密,这意味着不能在合理的时间内解密。 Please note that these are just two requirements, each have much more of them. 请注意,这些只是两个要求,每个要求都有更多。

Now, the intended usage is important. 现在, 预期用途很重要。 If you need to reuse passwords then you will need to store them somehow. 如果需要重用密码,则需要以某种方式存储它们。 There are several possibilities, including encryption. 有几种可能性,包括加密。 As you noted, the risk is to retrieve the key (someone can hack your OS, or hack your application when it uses the key, ...). 如您所述,风险在于获取密钥(有人可以破解您的操作系统,或者在使用密钥时入侵您的应用程序,...)。

I would warmly recommend to look for other possibilities (like authentication brokerage - offloading the authentication to someone else) before jumping into an architecture to store your passwords and keys. 我热烈建议在跳入用于存储密码和密钥的体系结构之前,寻找其他可能性(例如身份验证代理-将身份验证转移给其他人)。

If you want to recover passwords, hashing is out of option. 如果要恢复密码,则无法选择哈希。 Hash is straight up one-way algorithm. 哈希是一种单向算法。 So you have 2 options about encrypting passwords. 因此,您有2个关于加密密码的选项。

1- I keep the private key on my offline devices for special manual password recovery operation. 1-我将私钥保留在脱机设备上,以进行特殊的手动密码恢复操作。

You could do that, if you are certain that your offline device won't be compromised. 如果可以确定您的离线设备不会受到威胁,则可以这样做。

2- The private key is in the application but encrypted with a password. 2-私钥在应用程序中,但已用密码加密。

This could backfire since in case someone gets access to your code, they can deduce that you are encrypting passwords and storing them that way. 这可能适得其反,因为万一有人访问您的代码,他们可以推断出您正在加密密码并以这种方式存储它们。 That could motivate an attacker into accessing your private key. 这可能会激发攻击者访问您的私钥。

Given these 2 options, I'd say first one is more secure, since you only have to worry about devices physical security. 给定这两个选项,我想说第一个选项更安全,因为您只需要担心设备的物理安全性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM