加密密码

时间:2020-03-05 18:37:24  来源:igfitidea点击:

什么是最快且安全的加密密码方式(首选PHP),并且我们选择了哪种方法可移植?

换句话说,如果我以后将网站迁移到其他服务器,我的密码会继续有效吗?

就像我被告知的那样,我现在使用的方法取决于服务器上安装的库的确切版本。

解决方案:

如果我们为登录系统选择一种加密方法,那么速度就不是朋友,杰夫和托马斯·帕塔塞克(Thomas Ptacek)经常碰到密码有关,结论是我们应该使用负担得起的最慢,最安全的加密方法。

From Thomas Ptacek's blog:

  Speed is exactly what you don’t want in a password hash function.
  
  Modern password schemes are attacked with incremental password crackers.
  
  Incremental crackers don’t precalculate all possible cracked passwords. They consider each password hash individually, and they feed their dictionary through the password hash function the same way your PHP login page would. Rainbow table crackers like Ophcrack use space to attack passwords; incremental crackers like John the Ripper, Crack, and LC5 work with time: statistics and compute.
  
  The password attack game is scored in time taken to crack password X. With rainbow tables, that time depends on how big your table needs to be and how fast you can search it. With incremental crackers, the time depends on how fast you can make the password hash function run.
  
  The better you can optimize your password hash function, the faster your password hash function gets, the weaker your scheme is. MD5 and SHA1, even conventional block ciphers like DES, are designed to be fast. MD5, SHA1, and DES are weak password hashes. On modern CPUs, raw crypto building blocks like DES and MD5 can be bitsliced, vectorized, and parallelized to make password searches lightning fast. Game-over FPGA implementations cost only hundreds of dollars.

我和彼得在一起。开发人员似乎不了解密码。我们都选择(而且我也对此感到内and)MD5或者SHA1,因为它们速度很快。考虑一下(因为有人最近向我指出了这一点)没有任何意义。我们应该选择一个很慢的哈希算法。我的意思是,从规模上看,繁忙的网站会散列密码吗?每1/2分钟?谁在乎0.8秒与0.03秒的服务器明智时间?但是,这种额外的速度非常慢,可以阻止所有类型的常见蛮力攻击。

根据我的阅读,bcrypt是专门为安全密码散列而设计的。它基于河豚,并且有很多实现。

对于PHP,请查看PHPPass http://www.openwall.com/phpass/

对于使用.NET的任何人,请访问BCrypt.NET http://derekslager.com/blog/posts/2007/10/bcrypt-dotnet-strong-password-hashing-for-dotnet-and-mono.ashx

我并不一定要寻求最快的速度,而是要找到一个不错的平衡,为此代码开发的某些服务器运行速度相当慢,散列和存储密码的脚本需要5到6秒钟才能运行,而我已经将其范围缩小到哈希(如果我评论了哈希运行,则在1-2秒内完成)。

不必一定是最安全的,我现在没有在申请银行,但我当然不会将密码存储为纯文本格式。

应该指出的是,我们不想加密密码,而希望对其进行哈希处理。

加密的密码可以解密,让别人看到密码。哈希是一种单向操作,因此用户的原始密码(通过密码)消失了。

至于应该选择哪种算法使用当前接受的标准算法:

SHA-256密码:password1盐:PasswordSaltDesignedForThisQuestion

而且,当我们对用户密码进行哈希处理时,请确保也对它进行哈希处理。例如。:

{分块}

将盐添加到用户密码:

String s = HashStringSHA256("password1PasswordSaltDesignedForThisQuestion");

无论我们做什么,都不要编写自己的加密算法。这样做几乎可以保证(除非我们是密码学家)该算法中存在一个缺陷,使其难以破解。