gpt4 book ai didi

python - crypt.crypt 在 ubuntu 和 fedora 上的不同结果

转载 作者:太空宇宙 更新时间:2023-11-03 17:05:03 25 4
gpt4 key购买 nike

我想用 crypt 散列密码使用 blowfish 加密的模块。

在 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 上的 Python 3.7.1 来自默认存储库,而在 Ubuntu 上,来自官方存储库的 python 3.7.1 和我在 external PPA 上找到的都可以看到问题。 .

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

最佳答案

您的盐字符串在 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;
}

Ubuntu 18.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,所以没有测试。您可以复制测试程序,自行编译运行。

关于python - crypt.crypt 在 ubuntu 和 fedora 上的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54294135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com