python模块之hashlib加密

时间:2022-11-01 07:13:58
40、加密模块:hashlib
     1、
          >>> import hashlib
    >>> ret1 = hashlib.md5()
       >>> ret1.update(bytes('123',encoding = 'utf-8'))
    >>> ret1.hexdigest()
    '202cb962ac59075b964b07152d234b70'
2、因为:
     >>> s1 = '123'.encode('utf-8')
  >>> print(s1)
  b'123'
  >>> type(s1)
  <class 'bytes'>
   所以:
     >>> ha = hashlib.md5(b'oldboy')
     >>> ha.update('123'.encode('utf-8'))
  >>> ha.hexdigest()
  '78d0541c8c19b0b3cf3c4b5ebb8cda72'