pythonsha512在macosx上用crypt存储密码

2024-10-01 11:24:39 发布

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

我尝试生成加密的密码字符串,类似于Linux中的/etc/shadow。由于某些原因,我得到的输出是不同的。你知道我遗漏了什么吗?一个比另一个长(不算盐的部分)?在

#!/usr/bin/python
import crypt

alg = 6  # SHA512
salt = 'vb1tLY1qiY'
word = 'password'

insalt = '${}${}$'.format(alg, salt)

cryptWord = crypt.crypt(word, insalt)
print cryptWord

输出是:$6FMi11BJFsAc

如果我在Linux中这样生成:

^{pr2}$

输出是:$6$vb1tLY1qiY$WFHTa6CRShEuKg63vuPTYOVRK1oQiM6johIEs2JslF1904VhEdSXlHje74eB4uLXHrKNyZ4bPjSlWpZD6qIo71


Tags: 字符串密码linuxusretc原因wordsalt
1条回答
网友
1楼 · 发布于 2024-10-01 11:24:39

我可以使用lib。它不是作为python的一部分来安装的(至少在osx上),但是,您可以通过pip安装它。在

sudo easy_install pip
pip install passlib
python -c "from passlib.hash import sha512_crypt; import getpass,string,random; print sha512_crypt.using(salt=''.join([random.choice(string.ascii_letters + string.digits) for _ in range(16)]),rounds=5000).hash(getpass.getpass())"

https://gist.github.com/hbeatty/25db5847e7068335681db88248d0deaf

相关问题 更多 >