How to get the MD5 sum of a string using Python

0 min read 89 words

If you need to get the MD5 sum of a string using Python, then you can do the following.

Step 1

Firstly, we need to use the hashlib module:

import hashlib

Step 2

Now make sure that the input string is encoded correctly.

your_input = "this is your input string".encode('utf-8')

Step 3

Finally use the md5 function of the hashlib module, and get the hexdigest() value from it:

hashlib.md5(your_input).hexdigest()

Putting it all together

import hashlib

your_input = "this is your input string".encode('utf-8')
hashed = hashlib.md5(your_input).hexdigest()

print(hashed)

# --> af0874120fd6196ea1feeebdb6de0e54
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts