不同的结果密室,密室关于ubuntu vs fed

2024-09-30 22:13:25 发布

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

我想使用blowfish加密对crypt模块的密码进行散列。你知道吗

在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上,官方repos上的Python3.7.1和我在external PPA上发现的问题都可以看到。你知道吗

是否有任何环境变量或底层程序/库可以改变Python的行为?你知道吗


Tags: 模块importdefault密码onubuntulinuxpassword
1条回答
网友
1楼 · 发布于 2024-09-30 22:13:25

你的salt字符串在Ubuntu上无效。试着放弃那些美元的标志。你知道吗


从您链接的crypt模块的Python文档中:

This module implements an interface to the crypt(3) routine

salt (either a random 2 or 16 character string, possibly prefixed with $digit$ to indicate the method) which will be used to perturb the encryption algorithm. The characters in salt must be in the set [./a-zA-Z0-9], with the exception of Modular Crypt Format which prefixes a $digit$.

man 3 crypt

ERRORS

EINVAL: salt has the wrong format.

我写了一个测试程序来证实这一点:

#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 $

我手上没有软呢帽,所以我没试过。您可以复制测试程序并自己编译和运行它。你知道吗

相关问题 更多 >