The gods are silent-personal CSDN blog post directory
This article describes how to use Python's hashlib library to implement MD5 encryption on strings.
Official documentation of the hashlib library: hashlib — Secure hashes and message digests — Python 3.11.3 documentation
The hashlib library comes with Python 3, so no additional installation steps are required.
Assuming that the string to be encrypted is 'apple'
, the code for the encryption process is:
import hashlib
str1='apple'
md=hashlib.md5() #获取一个md5加密算法对象
md.update(str1.encode('utf-8'))
sign=md.hexdigest()
print(sign)
The last printed sign ( 1f3870be274f6c49b3e31a0c6728957f
) is the result of MD5 encryption.
Other references used in writing this article: