我想使用河豚加密来使用地窖模块散列一个密码。
在Fedora 29上,我得到了正确的结果:
$ python3.7
Python 3.7.2 (default, Jan 3 2019, 09:14:01)
[GCC 8.2.1 20181215 (Red Hat 8.2.1-6)] on linux
>>> import crypt
>>> crypt.crypt("password", "$2y$08$heregoesasaltstring...")
'$2y$08$heregoesasaltstring...ZR2mMC1niL.pkti1MfmoP.3XVbdoNHm'
>>>在Ubuntu 18.04上,它没有返回任何内容:
$ python3.7
Python 3.7.2 (default, Dec 25 2018, 03:50:46)
[GCC 7.3.0] on linux
>>> import crypt
>>> crypt.crypt("password", "$2y$08$heregoesasaltstring...")
>>>Fedora上的Python3.7.1来自默认的repos,而在Ubuntu上,从官方回复和我在外部PPA上找到的python3.7.1都可以看出问题。
是否有任何环境变量或底层程序/库可以更改Python的行为?
发布于 2019-01-21 16:43:21
您的盐串在Ubuntu上无效。试着扔掉所有的美元符号。
从您链接的crypt模块的Python文档中:
该模块实现了加密(3)例程salt (随机2或16字符串,可能以
$digit$作为前缀以指示方法)的接口,该接口将用于干扰加密算法。salt中的字符必须在set[./a-zA-Z0-9]中,但$digit$前缀的模块化密码格式除外。
来自man 3 crypt
偏误 EINVAL:盐格式不对。
我编写了一个测试程序来确认这一点:
#include <unistd.h>
#include <crypt.h>
#include <errno.h>
#include <stdio.h>
int main() {
char *s = crypt("password", "$2y$08$heregoesasaltstring...");
printf("%d\n%d\n%d\n", errno == EINVAL, errno == ENOSYS, errno == EPERM);
puts(s);
return 0;
}Ubuntu18.04的输出是
ibug@ubuntu:~/t $ gcc t.c -lcrypt
ibug@ubuntu:~/t $ a.out
1
0
0
Segmentation fault (core dumped)
139|ibug@ubuntu:~/t $我手边没有Fedora,所以我没有测试它。您可以复制测试程序并自己编译和运行它。
https://stackoverflow.com/questions/54294135
复制相似问题