简体   繁体   English

Python SHA512在MacOS X上使用crypt加密密码

[英]Python SHA512 salted passwords with crypt on MacOS X

I am trying to generate encrypted password strings, similar to /etc/shadow in Linux. 我正在尝试生成加密的密码字符串,类似于Linux中的/ etc / shadow。 For some reason the output I am getting is different. 出于某种原因,我得到的输出是不同的。 Any ideas what am I missing and is one has longer than the other (not counting the salt portion)? 任何想法我错过了什么比一个更长(不计算盐部分)?

#!/usr/bin/python
import crypt

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

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

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

The output is: $6FMi11BJFsAc 输出为: $6FMi11BJFsAc

If I generate this in Linux like this: 如果我在Linux中生成这样的:

mkpasswd --method=sha-512 --salt=vb1tLY1qiY password

The output is: $6$vb1tLY1qiY$WFHTa6CRShEuKg63vuPTYOVRK1oQiM6johIEs2JslF1904VhEdSXlHje74eB4uLXHrKNyZ4bPjSlWpZD6qIo71 输出为: $6$vb1tLY1qiY$WFHTa6CRShEuKg63vuPTYOVRK1oQiM6johIEs2JslF1904VhEdSXlHje74eB4uLXHrKNyZ4bPjSlWpZD6qIo71

I was able to use passlib. 我能够使用passlib。 It doesn't come installed as part of python (at least on OS X) but, you can install it via pip. 它不是作为python的一部分安装的(至少在OS X上),但是,你可以通过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 https://gist.github.com/hbeatty/25db5847e7068335681db88248d0deaf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM