简体   繁体   English

Python 2.4中的SHA256哈希

[英]SHA256 hash in Python 2.4

Is there a way I can calculate a SHA256 hash in Python 2.4 ? 有没有办法在Python 2.4中计算SHA256哈希? (I emphasize: Python 2.4) I know how to do it in Python 2.5 but unfortunately it's not available on my server and an upgrade will not be made. (我强调:Python 2.4)我知道如何在Python 2.5中实现它,但不幸的是它在我的服务器上不可用,并且不会进行升级。 I have the same problem as the guy in this question, but using Python 2.4. 我有同样的问题,因为在人这个问题,但使用Python 2.4。 Any help will be greatly appreciated. 任何帮助将不胜感激。

EDIT: Sorry, I mean SHA 256. I was too in a hurry. 编辑:对不起,我的意思是SHA 256.我太匆忙了。 Sorry again. 再次抱歉。

Yes you can. 是的你可以。 With Python 2.4, there was SHA-1 module which does exactly this. 在Python 2.4中,有一个SHA-1模块就是这样做的。 See the documentation . 请参阅文档

However, bear in mind that code importing from this module will cause DeprecationWarnings when run with newer Python. 但是,请记住,从较新的Python运行时,从此模块导入的代码将导致DeprecationWarnings。

Ok, as the requirement was tightened to be SHA-256, using the SHA-1 module in standard library isn't enough. 好的,由于要求被收紧为SHA-256,在标准库中使用SHA-1模块是不够的。 I'd suggest checking out pycrypto , it has a SHA-256 implementation. 我建议检查一下pycrypto ,它有一个SHA-256实现。 There are also windows binary releases to match older Pythons, follow the links from Andrew Kuchlings old PyCrypto page . 还有Windows二进制版本以匹配较旧的Pythons,请按照Andrew Kuchlings 旧PyCrypto页面中的链接进行操作。

You can use the sha module, if you want to stay compatible, you can import it like this: 您可以使用sha模块,如果要保持兼容,可以像这样导入:

try:
    from hashlib import sha1
except ImportError:
    from sha import sha as sha1

http://pypi.python.org/pypi/hashlib上有一个backported版本的hashlib,我只是向后移植了较新的hmac版本并将其放在http://pypi.python.org/pypi/hmac上

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

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