python中的bcrypt

2024-05-29 01:45:04 发布

您现在位置:Python中文网/ 问答频道 /正文

目前我正在尝试建立一个具有很高安全性的登录系统。

所以我想使用bcrypt,我还找到了第三方库, py-bcrypt

但是作者说这是一个纯python实现。

现在我在某个地方读到,不建议只在python中使用bcrypt,因为它太慢,这会导致安全漏洞。bcrypt应该在C中实现

有人能证实吗?现在我该怎么办?

我应该使用:

  • bcrypt(Python)
  • SHA512(来自hashlib)
  • 不同的东西

我正在使用谷歌应用程序引擎

编辑:http://packages.python.org/passlib/lib/passlib.hash.bcrypt.html#bcrypt-backends

It should be noted that the pure-python implementation (#4) is too slow to be useable, given the number of rounds currently required for security. Because of this, it is disabled by default, unless the environment variable PASSLIB_BUILTIN_BCRYPT="enabled" is set.


Tags: ofthepyis系统地方作者be
2条回答

把两者比较一下怎么样?下面是散列8000个随机位的密码和相应时间的代码:

哈希库:

#!/usr/bin/env python
import hashlib
import random

password = str(random.getrandbits(8000))
print hashlib.sha512(password).hexdigest()

Hashlib包括盐:

#!/usr/bin/env python
import hashlib
import random

password = str(random.getrandbits(8000))
salt = str(random.getrandbits(256))
print hashlib.sha512(password + salt).hexdigest()

bcrypt公司:

#!/usr/bin/env python
import bcrypt
import random

password = str(random.getrandbits(8000))
print bcrypt.hashpw(password,bcrypt.gensalt())

计时bcrypt:

$ time ./bcrypt_test.py 
$2a$12$Om3a3zKsCNAM/SLB3hq5w.HYukFwn4CJ73rjXYNUPgqckUx2uLEmG

real    0m0.401s
user    0m0.313s
sys 0m0.013s

计时哈希库:

$ time ./hashlib_test.py 
9e37eb4f164bbb1808833297d0244327e4faac109cd92729228f6e36d75d23044ac13a7a1907515cd6db44474b244678779e3ae4e97d8355c2069332aae52d61

real    0m0.032s
user    0m0.021s
sys 0m0.010s
$ 

试试passlib。它有一个bcrypt的C实现。

相关问题 更多 >

    热门问题