首先声明两个【hashlib】的【md5】对象:

(djangoProject_Noted) adamhuan:djangoProject_Noted/ $ python                                                                                                                  [23:19:27]
Python 3.10.0 (v3.10.0:b494f5935c, Oct  4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> 
>>> md5_1 = hashlib.md5()
>>> md5_2 = hashlib.md5()
>>>

向两个对象中写入明文的字符串:

>>> md5_1.update(b'1')
>>> md5_1.hexdigest()
'c4ca4238a0b923820dcc509a6f75849b'
>>> md5_1.update(b'23')
>>> md5_1.hexdigest()
'202cb962ac59075b964b07152d234b70'
>>> 

>>> md5_2.update(b'123')
>>> md5_2.hexdigest()
'202cb962ac59075b964b07152d234b70'
>>> 

可以看到,如果想要重新生成字符串,应该重新创建一个MD5对象,否则,就只是在之前的基础上累加更新。


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

隐藏
变装