hashlib

Porting hashs from php's crypt() to python

十年热恋 提交于 2019-12-23 17:23:10
问题 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. 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. I've

Python and hashlib module

让人想犯罪 __ 提交于 2019-12-23 10:53:23
问题 I've just installed Python 2.6.6 from sources and what I get: >>> import hashlib Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.6/hashlib.py", line 136, in <module> md5 = __get_builtin_constructor('md5') File "/usr/local/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor import _md5 ImportError: No module named _md5 回答1: Install openssl-dev and rebuild. 回答2: I have just tested this on my 2.6.6 installation and I have had no

Difference in SHA512 between python hashlib and sha512sum tool

為{幸葍}努か 提交于 2019-12-23 08:58:21
问题 I am getting different message digests from the linux 'sha512sum' tool and the python hashlib library. Here is what I get on my Ubuntu 8.10: $ echo test | sha512sum 0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123 - $ python Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib >>> hashlib.sha512("test")

Is there any way to use non-openssl md5 for hashlib in python?

老子叫甜甜 提交于 2019-12-22 10:27:08
问题 I generate md5 content hashes for upload verification, but it has recently come to my attention that this will fail for any users running on a FIPS enabled machine. FIPS disables openssl md5, resulting in a ValueError when I try to initialize hashlib. Normally I would use SHA instead, but I'm relying on an external service which requires a content-md5 header. My question is this: Is there any way to force Python to use a non-openssl hashing function? There was some talk here about adding a

Convert integer to a random but deterministically repeatable choice

只谈情不闲聊 提交于 2019-12-22 05:07:10
问题 How do I convert an unsigned integer (representing a user ID) to a random looking but actually a deterministically repeatable choice? The choice must be selected with equal probability (irrespective of the distribution of the the input integers). For example, if I have 3 choices, i.e. [0, 1, 2] , the user ID 123 may always be randomly assigned choice 2, whereas the user ID 234 may always be assigned choice 1. Cross-language and cross-platform algorithmic reproducibility is desirable. I'm

HMAC signing requests in Python

拥有回忆 提交于 2019-12-21 12:16:42
问题 I'm trying to create an HMAC-SHA512 signed request for an API call in Python 3.4 using the requests library. I'm trying to follow docs, but am hitting this error: AttributeError: '_hashlib.HASH' object has no attribute 'new' Here's some code. It's failing with the error on the hmac constructor. It's fine if I try and pass hashlib.md5() or omit the digest parameter entirely. I'm not sure if I'm signing the request properly afterwards as I haven't got that far yet. The docs for the service I'm

python error “AttributeError: 'module' object has no attribute 'sha1'”

血红的双手。 提交于 2019-12-20 02:27:14
问题 i need your help, How to correct an error AttributeError: 'module' object has no attribute 'sha1', When I start the command example import random or import hashlib I get such a result root@thinkad:~# python Python 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import random Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/random.py", line 49, in <module>

Compare result from hexdigest() to a string

五迷三道 提交于 2019-12-19 02:54:13
问题 I've got a generated MD5-hash, which I would like to compare to another MD5-hash from a string. The statement below is false, even though they look the same when you print them and should be true. hashlib.md5("foo").hexdigest() == "acbd18db4cc2f85cedef654fccc4a4d8" Google told me that I should encode the result from hexdigest() , since it doesn't return a string. However, the code below doesn't seem to work either. hashlib.md5("foo").hexdigest().encode("utf-8") == "foo".encode("utf-8") 回答1:

Max limit of bytes in method update of Hashlib Python module

只愿长相守 提交于 2019-12-18 09:02:29
问题 I am trying to compute md5 hash of a file with the function hashlib.md5() from hashlib module. So that I writed this piece of code: Buffer = 128 f = open("c:\\file.tct", "rb") m = hashlib.md5() while True: p = f.read(Buffer) if len(p) != 0: m.update(p) else: break print m.hexdigest() f.close() I noted the function update is faster if I increase Buffer variable value with 64, 128, 256 and so on. There is a upper limit I cannot exceed? I suppose it might only a RAM memory problem but I don't

How to correct TypeError: Unicode-objects must be encoded before hashing?

安稳与你 提交于 2019-12-17 02:28:15
问题 I have this error: Traceback (most recent call last): File "python_md5_cracker.py", line 27, in <module> m.update(line) TypeError: Unicode-objects must be encoded before hashing when I try to execute this code in Python 3.2.2 : import hashlib, sys m = hashlib.md5() hash = "" hash_file = input("What is the file name in which the hash resides? ") wordlist = input("What is your wordlist? (Enter the file name) ") try: hashdocument = open(hash_file, "r") except IOError: print("Invalid file.") raw