将哈希从php的crypt()移植到python [英] Porting hashs from php's crypt() to python

查看:134
本文介绍了将哈希从php的crypt()移植到python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有与PHP的crypt()函数相似的python,其执行方式类似,生成随机盐并将其嵌入保存的字符串中.

I was wondering if there is a python cognate to PHP's crypt() function that performs in a similar way, generating a random salt and embedding it within the saved string.

我有一个哈希密码表,该哈希密码表是使用$5$字符串键创建的,用于设置基于SHA256的加盐密码.这些哈希具有固定间隔固定在两端的附加记录熵,但是将这些字符从字符串中分离出来并获得核心哈希值是微不足道的,根本不是问题.

I have a table of hashed passwords that were created using the $5$ string key to setup a SHA256 based salted cryptogram. These hashes had some additional recorded entropy attached to both ends at a fixed interval, but splitting these characters off the string and getting the core hash is trivial and not a problem at all.

我看过python文档,在hashlib中找不到任何似乎利用了php crypt()相同语法的方法.在PHP中使用的方法(输入格式在盐,算法和回合之间用美元符号分隔)是该语言所独有的吗?

I've looked at the python documentation and can't find any methods in hashlib that seem to utilize the same syntax from php's crypt(). Is the approach utilized in PHP (the input format split with dollar signs between salt, algo and rounds) unique to the language?

谢谢.

似乎python自身的本机crypt函数的修订版将使用类似于PHP的过程.从3.3版预发布文档中:

It looks as though the revised version of python's own native crypt function is going to utilize procedures similar to that of PHP. From the 3.3 pre-release documentation:

http://docs.python.org/dev/library/crypt.html

编辑:

最后找到了Passlib,这是一个在纯python中提供此功能的库.

Finally found Passlib, a library that provides this functionality in pure python.

http://packages.python.org/passlib/index.html

推荐答案

它看起来与 FreeBSD的地穴(请参见联机帮助页中的模块化地穴").我真的不记得在Linux或其他操作系统中是否也是如此,但这似乎表明它不是唯一的.

It certainly looks very similar to FreeBSD's crypt (see "modular crypt" in the manpage). I don't really recall if it's the same way in Linux or other but this seems to indicate it's not unique.

据我所知,在Python中没有直接等效的功能,但是,由于hashlib应该支持加密算法本身,因此滚动自己的密码应该不会太难.

There's no direct equivalent in Python as far as I know, but it shouldn't be too hard to roll your own since the encryption algorithms themselves should be supported in hashlib.

这篇关于将哈希从php的crypt()移植到python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆