To create an MD5 hash from a string in Python, you can use the hashlib
module. Here's an example:
main.py305 chars14 lines
Output:
main.py112 chars2 lines
In this example, we first define our string and then use the encode()
method to convert it to bytes in the UTF-8 format. Next, we use the hashlib.md5()
method to create an MD5 hash object and pass in the encoded string as a parameter. Finally, we use the hexdigest()
method to get the hexadecimal representation of the MD5 hash.
gistlibby LogSnag