描述: hashlib.new(), md5().update(), md5(), hexdigest()
代码:
# -*- coding: utf8 -*-
from hashlib import md5
import hashlib
if __name__ == '__main__':
s = 'hello world!'
b = s.encode('utf-8')
print('md5: %s' % md5(b).hexdigest())
print('md5 new: %s' % hashlib.new('md5', b).hexdigest())
m = md5()
m.update(b)
print("first update: %s" % m.hexdigest())
m.update(b)
print("second update: %s" % m.hexdigest())
print('update effect: %s' % md5(b+b).hexdigest())
输出:
md5: fc3ff98e8c6a0d3087d515c0473f8677
md5 new: fc3ff98e8c6a0d3087d515c0473f8677
first update: fc3ff98e8c6a0d3087d515c0473f8677
second update: 6b5bcab6aaa88178218c59f0a4a52adf
update effect: 6b5bcab6aaa88178218c59f0a4a52adf