Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse an instance of hashlib.md5

Tags:

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 see any way to flush or reset the instance.

like image 478
Steve Avatar asked Nov 09 '10 12:11

Steve


People also ask

What does Hashlib MD5 do?

MD5 hash in Python: This hash function is available in the hashlib module of Python. It takes a sequence of bytes as input and returns the 128-bit hash value as output. The primary use of the hash function is to check data integrity, but it has security issues.

Does Hashlib use OpenSSL?

Hashlib now uses SHA3 and SHAKE from OpenSSL 1.1. 1 and newer.

What is import Hashlib?

The Python hashlib module is an interface for hashing messages easily. This contains numerous methods which will handle hashing any raw message in an encrypted format. The core purpose of this module is to use a hash function on a string, and encrypt it so that it is very difficult to decrypt it.


1 Answers

Why do you think it's inefficient to make a new one? It's a small object, and objects are created and destroyed all the time. Use a new one, and don't worry about it.

like image 73
Ned Batchelder Avatar answered Oct 31 '22 23:10

Ned Batchelder