Questions tagged [hashlib]

Hashlib is a Python module that implements a common interface to many different secure hash and message digest algorithms.

427 questions
7
votes
6 answers

the fastest way to create checksum for large files in python

i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on…
pixelblender
  • 181
  • 3
  • 4
  • 8
6
votes
3 answers

Hashlib hashes not comparing properly

Heres my code: import hashlib real = hashlib.sha512("mom") status = True while status: inp = raw_input("What's the password?") converted = hashlib.sha512(inp) if converted == real: print "Access granted!" status =…
user775171
6
votes
1 answer

How to get the same hash in Python3 and Mac / Linux terminal?

How can I get the same sha256 hash in terminal (Mac/Linux) and Python? Tried different versions of the examples below, and search on StackOverflow. Terminal: echo 'test text' | shasum -a…
Punnerud
  • 7,195
  • 2
  • 54
  • 44
6
votes
5 answers

Persisting hashlib state

I'd like to create a hashlib instance, update() it, then persist its state in some way. Later, I'd like to recreate the object using this state data, and continue to update() it. Finally, I'd like to get the hexdigest() of the total cumulative run…
anthony
  • 40,424
  • 5
  • 55
  • 128
6
votes
1 answer

Securely overwrite Python variables in RAM?

I'm making a program in Python that will involve hashing a password. Assuming I use this to get the password: import getpass password = getpass.getpass("Password: ") And then hash it, is there any way to securely remove all traces of the unhashed…
tkbx
  • 15,602
  • 32
  • 87
  • 122
6
votes
1 answer

Hashlib: optimal size of chunks to be used in md5.update()

This is in reference to Get MD5 hash of big files in Python and Hashlib in Windows and Linux In responses to both these questions, it is advised to use larger chunks of data in the function md5.update() to improve performance. All testing I have…
Verma
  • 956
  • 6
  • 21
5
votes
5 answers

Unable to import "hashlib"

I'm trying to encrypt a string in sha1 and I get an error from the server: "No Module Named hashlib" By using the following code: import hashlib encrypted = hashlib.sha1(string) encrypted = encrypted.digest() I'll appreciate any help, Thanks, Guy…
user330885
5
votes
1 answer

Difference between `block_size` and `digest_size` in hashlib?

I was going through the Python hashlib package documentation and wanted some clarification on two hash object attributes (namely hash.block_size and hash.digest_size). Here is the definition of each attribute: hash.digest_size= "The size of the…
DGav
  • 271
  • 3
  • 14
5
votes
0 answers

Instagram Scraping with endpoints requires authentication for all requests

As you know, Instagram announced they has changed their endpoint apis this month. Looks like in the wake of Cambridge Analytica instagram has changed up their endpoint formats and require a logged in user session for all requests..... Not sure which…
supernova
  • 398
  • 1
  • 3
  • 15
5
votes
3 answers

Python and hashlib module

I've just installed Python 2.6.6 from sources and what I get: >>> import hashlib Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/hashlib.py", line 136, in md5 =…
zerkms
  • 249,484
  • 69
  • 436
  • 539
5
votes
2 answers

ruby sha 256 hexidigest values are different from what python generates

I am using hashlib library in python and Digest::SHA256.hexdigest library in ruby With python I tried, import hashlib hasher = hashlib.sha256() hasher.update("xyz") hasher.digest() hash = hasher.hexdigest() print hash output :…
Hound
  • 837
  • 17
  • 31
5
votes
1 answer

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte

I want to convert a byte variable to string. Of course, there are previous questions related to mine. However, trying to hash in md5() the content of a file this way: import hashlib with open("C:\\boot.ini","r") as f: …
user3522371
5
votes
1 answer

How to update hashlib.md5 hasher using existing hasher in python?

I have got cached instance of hasher: m1 = hashlib.md5() m1.update(b'very-very-long-data') cached_sum = m1 and I would like to update external hasher with a sum cached before: def append_cached_hash(external_hasher): # something like this …
Andrew
  • 2,055
  • 2
  • 20
  • 27
5
votes
2 answers

Difference between Hashlib and System.Security.Cryptography.HashAlgorithm

I am trying to understand how hashing algorithms works, specially SHA3-512. To see how it works I searched for codes in Google and came across with Hashlib. The code doesn't work as I don't have the Hashlib library (not sure what it should be…
Giliweed
  • 4,997
  • 8
  • 26
  • 35
5
votes
1 answer

Is there a faster way (than this) to calculate the hash of a file (using hashlib) in Python?

My current approach is this: def get_hash(path=PATH, hash_type='md5'): func = getattr(hashlib, hash_type)() with open(path, 'rb') as f: for block in iter(lambda: f.read(1024*func.block_size, b''): func.update(block) …
Deneb
  • 981
  • 2
  • 9
  • 25