Hashlib is a Python module that implements a common interface to many different secure hash and message digest algorithms.
Questions tagged [hashlib]
361 questions
15
votes
6 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)
![](../../users/profiles/688266.webp)
Kamilski81
- 12,534
- 29
- 96
- 143
14
votes
2 answers
Is there a significant overhead by using different versions of sha hashing (hashlib module)
The hashlib Python module provides the following hash algorithms constructors: md5(), sha1(), sha224(), sha256(), sha384(), and sha512().
Assuming I don't want to use md5, is there a big difference in using, say, sha1 instead of sha512? I want to…
![](../../users/profiles/185053.webp)
Emilien
- 2,661
- 2
- 20
- 30
11
votes
1 answer
Why the hashlib and hmac are generating different hash values?
In Python 2.7,
my = "my"
key = "key"
print(hashlib.sha256(my + key).hexdigest())
print(hmac.new(my, key,…
![](../../users/profiles/878206.webp)
Er Dj
- 111
- 1
- 1
- 3
11
votes
1 answer
Unsupported hash type error while installing hashlib using pip3
I am trying to install the hashlib library for Python 3.6.0. Using pip3:
pip3 install hashlib
I get:
Collecting hashlib
Downloading hashlib-20081119.zip (42kB)
100% |████████████████████████████████| 51kB 1.6MB/s
Complete output from…
![](../../users/profiles/4005308.webp)
Lars S
- 484
- 4
- 16
10
votes
4 answers
python error "AttributeError: 'module' object has no attribute 'sha1'"
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,…
![](../../users/profiles/2159967.webp)
Droid
- 1,318
- 8
- 22
- 34
10
votes
5 answers
python (django) hashlib vs Nodejs crypto
I'm porting over a Django site to Node.js and I am trying to re implement the Django set password method in Node. This is the Django code
from django.utils.crypto import (
pbkdf2, get_random_string)
import hashlib
password = 'text1'
algorithm…
![](../../users/profiles/422121.webp)
imns
- 4,728
- 11
- 51
- 77
9
votes
3 answers
How to hash a variable in Python?
This example works fine example:
import hashlib
m = hashlib.md5()
m.update(b"Nobody inspects")
r= m.digest()
print(r)
Now, I want to do the same thing but with a variable: var= "hash me this text, please". How could I do it following the same logic…
user3522371
9
votes
2 answers
What's a C# equivalent of hexdigest in Python 3.2?
I'm currently working on a project to convert a Python 3.2 program to C#.
In the python program there's a line of code which returns a string object of double length, containing only hexadecimal digits.
The bit of code in the Python program is:
if…
![](../../users/profiles/1292730.webp)
GeorgePotter
- 840
- 1
- 10
- 17
8
votes
1 answer
Convert string to random but deterministically repeatable uniform probability
How do I convert a string, e.g. a user ID plus salt, to a random looking but actually a deterministically repeatable uniform probability in the semi-open range [0.0, 1.0)? This means that the output is ≥ 0.0 and < 1.0. The output distribution must…
![](../../users/profiles/832230.webp)
Acumenus
- 41,481
- 14
- 116
- 107
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() ==…
![](../../users/profiles/404691.webp)
nip3o
- 3,096
- 4
- 20
- 28
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…
![](../../users/profiles/78374.webp)
Stefano Borini
- 125,999
- 87
- 277
- 404
8
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 |…
![](../../users/profiles/97099.webp)
KIV
- 735
- 8
- 12
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…
![](../../users/profiles/1047786.webp)
ib.lundgren
- 1,454
- 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…
![](../../users/profiles/13009.webp)
Greg
- 39,830
- 86
- 217
- 286
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).…
![](../../users/profiles/832230.webp)
Acumenus
- 41,481
- 14
- 116
- 107