首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >crypt.crypt对的不同结果

crypt.crypt对的不同结果
EN

Stack Overflow用户
提问于 2019-01-21 16:31:35
回答 1查看 102关注 0票数 1

我想使用河豚加密来使用地窖模块散列一个密码。

在Fedora 29上,我得到了正确的结果:

代码语言:javascript
复制
$ 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上,它没有返回任何内容:

代码语言:javascript
复制
$ 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的行为?

EN

回答 1

Stack Overflow用户

发布于 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:盐格式不对。

我编写了一个测试程序来确认这一点:

代码语言:javascript
复制
#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的输出是

代码语言:javascript
复制
ibug@ubuntu:~/t $ gcc t.c -lcrypt
ibug@ubuntu:~/t $ a.out
1
0
0
Segmentation fault (core dumped)
139|ibug@ubuntu:~/t $

我手边没有Fedora,所以我没有测试它。您可以复制测试程序并自己编译和运行它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54294135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档