Hashlib is a Python module that implements a common interface to many different secure hash and message digest algorithms.
Questions tagged [hashlib]
427 questions
464
votes
9 answers
Generating an MD5 checksum of a file
Is there any simple way of generating (and checking) MD5 checksums of a list of files in Python? (I have a small program I'm working on, and I'd like to confirm the checksums of the files).

Alexander
- 5,661
- 6
- 24
- 19
457
votes
10 answers
How to correct TypeError: Unicode-objects must be encoded before hashing?
I have this error:
Traceback (most recent call last):
File "python_md5_cracker.py", line 27, in
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,…

JohnnyFromBF
- 9,873
- 10
- 45
- 59
210
votes
13 answers
Get the MD5 hash of big files in Python
I have used hashlib (which replaces md5 in Python 2.6/3.0), and it worked fine if I opened a file and put its content in the hashlib.md5() function.
The problem is with very big files that their sizes could exceed the RAM size.
How can I get the MD5…

JustRegisterMe
- 2,147
- 3
- 15
- 7
182
votes
9 answers
Hashing a file in Python
I want python to read to the EOF so I can get an appropriate hash, whether it is sha1 or md5. Please help. Here is what I have so far:
import hashlib
inputFile = raw_input("Enter the name of the file:")
openedFile = open(inputFile)
readFile =…

user3358300
- 1,919
- 2
- 13
- 6
45
votes
7 answers
Hashing in SHA512 using a salt? - Python
I have been looking through ths hashlib documentation but haven't found anything talking about using salt when hashing data.
Help would be great.

RadiantHex
- 24,907
- 47
- 148
- 244
32
votes
3 answers
32
votes
4 answers
Error importing hashlib with python 2.7 but not with 2.6
I'm on Solaris 10 (x86).
Until now, I was using python2.6. Today, I installed python2.7 and I have a weird error occuring when importing hashlib on 2.7, but not on 2.6:
Python 2.6:
root@myserver [PROD] # python2.6 -c "import hashlib"
root@myserver…

SuperPython
- 1,007
- 2
- 12
- 24
30
votes
4 answers
ImportError: cannot import name md5
Don't really know what's going on here, I need to deploy my flask app on elastic beanstalk but somehow changed the path and can't run python application.py anymore
[dotnet --info]
.NET Core SDK (reflecting any global.json):
Version: 2.1.701
…

Chelsea Ip Tze Hwan
- 351
- 1
- 4
- 7
29
votes
1 answer
How to fix Unicode encode error using the hashlib module?
After multiple searches I have not been able to determine how to avoid an error stating: "Unicode-objects must be encoded before hashing" when using this code:
pwdinput = input("Now enter a password:")
pwd = hashlib.sha1()
…

Nate
- 293
- 1
- 3
- 4
29
votes
1 answer
Failed to install hashlib, python 3, debian
The software fails to install. Any help in resolving this would be appreciated.
I believe that the error is probably a dependency error.
Running setup.py (path:/tmp/pip-build-9rlb94_r/hashlib/setup.py) egg_info for package hashlib
…

dipl0
- 1,017
- 2
- 13
- 36
25
votes
3 answers
Using hashlib to compute md5 digest of a file in Python 3
With python 2.7 the following code computes the mD5 hexdigest of the content of a file.
(EDIT: well, not really as answers have shown, I just thought so).
import hashlib
def md5sum(filename):
f = open(filename, mode='rb')
d = hashlib.md5()
…

kriss
- 23,497
- 17
- 97
- 116
23
votes
7 answers
How do I decrypt using hashlib in python?
I know how to encrypt:
encrypted = hashlib.sha256('1234').hexdigest()
But I am not sure, how to decrypt this?
decrypted = decrypt(encrypted)

Kamilski81
- 14,409
- 33
- 108
- 161
21
votes
2 answers
How to reuse an instance of hashlib.md5
How do you flush (or reset) and reuse an instance of hashlib.md5 in python? If I am performing multiple hashing operations in a script, it seems inefficient to use a new instance of hashlib.md5 each time, but from the python documentation I don't…

Steve
- 219
- 2
- 3
19
votes
5 answers
'frozenset' object is not callable
When I attempt to import hashlib in any context, it throws this error:
File "", line 1, in
File "build/bdist.macosx-10.11-intel/egg/hashlib.py", line 115, in
"""
TypeError: 'frozenset' object is not callable
Any idea…

Alex Beals
- 1,965
- 4
- 18
- 26
18
votes
3 answers
basics of python encryption w/ hashlib sha1
I'm struggling to fully understand how encryption works and is coded, particularly with python. I'm just trying to get the basics down and create code in the simplest form.
I'm going to be passing a userID between two different sites, but obviously…

adam
- 3,498
- 6
- 34
- 46