How can I vendorize bcrypt in a PHP application (and should I)?

99封情书 提交于 2019-12-01 17:36:10

Is my lack of PHP knowledge getting the best of me? Can I really use one of the already-created implementations?

Unfortunately, you are correct. Prior to 5.3.0 PHP didn't support bcrypt by default. Instead, it relied on the OS's support (check the CRYPT_BLOWFISH constant). As you've pointed out Suhosin is an option in that case.

Should I instead just create a simple loooping function that calls sha1() or md5() repeatedly for some configurable number of times?

The best advice when it comes to cryptography is "don't roll your own." Repeated calls to sha1() or md5() may or may not increase security.

The authors of bcrypt on the other hand explain their design decisions on this paper.

Unfortunately you can't use bcrypt with Blowfish unless you're on PHP 5.3 or using the Suhosin extension or possibly that the operating system has support for Blowfish in its bcrypt implementation.

So your best bet in this case would be to use SHA-256 or SHA-512 with key stretching (and of course, salt). But rolling your own solution is never a good idea when it comes to security.

One of the benefits of phpass that you didn't touch upon was that it automatically falls back to using DES and finally MD5 as an underlying cipher if CRYPT_BLOWFISH is not available. The wrapper uses these in such a way that even the md5 implementation is significantly more secure than a simple hash.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!