Hashlib is a Python module that implements a common interface to many different secure hash and message digest algorithms.
Questions tagged [hashlib]
361 questions
383
votes
6 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).
![](../../users/profiles/408168.webp)
Alexander
- 4,830
- 5
- 21
- 19
369
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,…
![](../../users/profiles/906738.webp)
JohnnyFromBF
- 8,300
- 10
- 43
- 50
194
votes
13 answers
Get 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 hashlib.md5() function.
The problem is with very big files that their sizes could exceed RAM size.
How to get the MD5 hash of a…
![](../../users/profiles/134065.webp)
JustRegisterMe
- 1,987
- 2
- 14
- 7
112
votes
6 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 =…
![](../../users/profiles/3358300.webp)
user3358300
- 1,219
- 2
- 10
- 5
42
votes
6 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.
![](../../users/profiles/208827.webp)
RadiantHex
- 22,589
- 43
- 141
- 236
31
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…
![](../../users/profiles/1472039.webp)
SuperPython
- 915
- 1
- 8
- 21
30
votes
3 answers
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()
…
![](../../users/profiles/843223.webp)
Nate
- 293
- 1
- 3
- 4
29
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
…
![](../../users/profiles/11547413.webp)
Chelsea Ip Tze Hwan
- 331
- 1
- 3
- 4
24
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()
…
![](../../users/profiles/168465.webp)
kriss
- 21,366
- 15
- 89
- 109
22
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
…
![](../../users/profiles/3353752.webp)
dipl0
- 827
- 1
- 8
- 24
19
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…
![](../../users/profiles/501896.webp)
Steve
- 199
- 1
- 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…
![](../../users/profiles/3951475.webp)
Alex Beals
- 1,365
- 3
- 14
- 24
16
votes
1 answer
Operations on Python hashes
I've got a rather strange problem. For a Distributed Hash Table I need to be able to do some simple math operations on MD5 hashes. These include a sum (numeric sum represented by the hash) and a modulo operation. Now I'm wondering what the best way…
![](../../users/profiles/49561.webp)
cdecker
- 4,042
- 6
- 41
- 71
15
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…
![](../../users/profiles/361897.webp)
adam
- 3,288
- 5
- 28
- 45