Hashlib is a Python module that implements a common interface to many different secure hash and message digest algorithms.
Questions tagged [hashlib]
427 questions
9
votes
3 answers
Difference in SHA512 between python hashlib and sha512sum tool
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 |…

KIV
- 745
- 8
- 12
8
votes
1 answer
Installing hashLib gives SyntaxError: Missing parentheses in call to 'print'
I needed a simple hash function for passwords and thought I could use hashlib. PyCharm suggested to install it by running pip install hashLib.
But now PyCharm is complaining about a syntax error in the library:
Collecting hashLib
Using cached…

meme
- 81
- 1
- 1
- 3
8
votes
4 answers
Invalid hash, timestamp, and key combination in Marvel API Call
I'm trying to form a Marvel API Call.
Here's a link on authorization:
https://developer.marvel.com/documentation/authorization
I'm attempting to create a server-side application, so according to the link above, I need a timestamp, apikey, and hash…

Philosopher-Programmer
- 153
- 1
- 9
8
votes
3 answers
Compare result from hexdigest() to a string
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() ==…

nip3o
- 3,346
- 4
- 24
- 29
8
votes
2 answers
Convert unique numbers to md5 hash using pandas
Good morning, All.
I want to convert my social security numbers to a md5 hash hex number. The outcome should be a unique md5 hash hex number for each social security number.
My data format is as follows:
ob =…

Dave
- 6,968
- 7
- 26
- 32
8
votes
1 answer
HMAC signing requests in Python
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…

Ludo
- 2,739
- 2
- 28
- 42
8
votes
2 answers
hashlib / md5. Compatibility with python 2.4
python 2.6 reports that the md5 module is obsolete and hashlib should be used. If I change import md5 to import hashlib I will solve for python 2.5 and python 2.6, but not for python 2.4, which has no hashlib module (leading to a ImportError, which…

Stefano Borini
- 138,652
- 96
- 297
- 431
7
votes
3 answers
SHA1 hash differ between openssl and hashlib/pycrypto
Why does the hash from using openssl differ from the ones I get in python?
$ echo "Lorem ipsum" | openssl dgst -sha1 -hex
(stdin)= d0c05753484098c61e86f402a2875e68992b5ca3
$ python
>>> from hashlib import sha1
>>> sha("Lorem…

ib.lundgren
- 1,524
- 14
- 15
7
votes
4 answers
Determine whether any files have been added, removed, or modified in a directory
I'm trying to write a Python script that will get the md5sum of all files in a directory (in Linux). Which I believe I have done in the code below.
I want to be able to run this to make sure no files within the directory have changed, and no…

Greg
- 45,306
- 89
- 231
- 297
7
votes
1 answer
How can i get sha3-512 hash in C#?
exaple, string "test" in https://md5calc.com/hash/sha3-512/test gives me "9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7b710110c0a678288166e7fbe796883a4f2e9b3ca9f484f521d0ce464345cc1aec96779149c14"
but
using HashLib; // from…

Apepenkov
- 415
- 1
- 3
- 10
7
votes
4 answers
Convert integer to a random but deterministically repeatable choice
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).…

Asclepius
- 57,944
- 17
- 167
- 143
7
votes
2 answers
Python: How to create a 16 character long digest using hashlib.md5 algorithm?
Php's md5 function takes an optional second argument which, if true, returns a smaller hash of length 16 instead of the normal 32 character long hash.
How can we do the same using python's hashlib.md5.

Mahammad Adil Azeem
- 9,112
- 13
- 57
- 84
7
votes
3 answers
Compare md5 hashes of two files in python
I want to compare hashes of two files. But no matter if files are different or not, even with different hashes comparison results True
Here is the code:
import hashlib
hasher1 = hashlib.md5()
afile1 = open('canvas.png', 'rb')
buf1 =…

VAGrus
- 73
- 1
- 1
- 6
7
votes
3 answers
SHA 512 crypt output written with Python code is different from mkpasswd
Running mkpasswd -m sha-512 -S salt1234 password results in the following:
$6$salt1234$Zr07alHmuONZlfKILiGKKULQZaBG6Qmf5smHCNH35KnciTapZ7dItwaCv5SKZ1xH9ydG59SCgkdtsTqVWGhk81
I have this snippet of Python code that I thought would output the same,…

user1720897
- 1,216
- 3
- 12
- 27
7
votes
3 answers
Python SHA1 Integer
I did two SHA1 in C code, one is for a string, and another is for a integer, and get different result.
SHA_init(&ctx);
SHA_update(&ctx, "1234", 4);
sha = SHA_final(&ctx);
unsigned n = 1234;
SHA_init(&ctx);
SHA_update(&ctx, &n, sizeof(n));
sha =…

Weicuan Yan
- 71
- 1
- 5