Python 2.4 中的 SHA256 哈希
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1328155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SHA256 hash in Python 2.4
提问by hyperboreean
Is there a way I can calculate a SHA256 hash in Python 2.4 ? (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. I have the same problem as the guy in thisquestion, but using Python 2.4. Any help will be greatly appreciated.
有没有办法在 Python 2.4 中计算 SHA256 哈希?(我强调:Python 2.4)我知道如何在 Python 2.5 中执行此操作,但不幸的是它在我的服务器上不可用,并且不会进行升级。我有同样的问题,因为在人这个问题,但使用Python 2.4。任何帮助将不胜感激。
EDIT: Sorry, I mean SHA 256. I was too in a hurry. Sorry again.
编辑:对不起,我的意思是 SHA 256。我太赶时间了。再次抱歉。
回答by af.
Yes you can. With Python 2.4, there was SHA-1 module which does exactly this. See the documentation.
是的你可以。在 Python 2.4 中,有一个 SHA-1 模块可以做到这一点。请参阅文档。
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. I'd suggest checking out pycrypto, it has a SHA-256 implementation. There are also windows binary releases to match older Pythons, follow the links from Andrew Kuchlings old PyCrypto page.
好的,由于要求已收紧为 SHA-256,因此在标准库中使用 SHA-1 模块是不够的。我建议检查一下pycrypto,它有一个 SHA-256 实现。还有 Windows 二进制版本可以匹配较旧的 Python,请访问 Andrew Kuchlings旧 PyCrypto 页面中的链接。
回答by tonfa
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
回答by Laurence Rowe
There is a backported version of hashlib at http://pypi.python.org/pypi/hashliband I just backported the newer hmac version and put it up at http://pypi.python.org/pypi/hmac
在http://pypi.python.org/pypi/hashlib有一个反向移植版本的 hashlib,我只是向后移植了较新的 hmac 版本并将其放在http://pypi.python.org/pypi/hmac