# !/user/bin/python
# -*- coding: utf-8 -*-

import hashlib

# 可提供MD5算法 , 防止内页被篡改 (若内页未被篡改, MD5的值是不变的)
m = hashlib.md5()
m.update(b"hello")
print(m.hexdigest())  # 生成md5值.
m.update(b"it's me")  # 不是用it's me 取代了hello, 而是加在了hello的后面, 所以md5值应该和直接写helloit's me的md5值一样.
print(m.hexdigest())
m.update(b"it's been a long time since we spoken...")
print(m.hexdigest())


m2 = hashlib.md5()
m2.update(b"helloit's me")
print(m.hexdigest())  # 为什么和第三句话的md5值一样, 不是应该和第二句话的md5值一样吗? TODO

s2 = hashlib.sha1
s2.update(b"helloit's me")
print(s2.hexdigest)


import hmac  # 双重加密
h = hmac.new("12345", "you are 250", encode(encoding="utf-8")) # 为什么不行?TODO
print(h.digest())
print(h.hexdigest())

 

相关文章:

  • 2021-07-13
  • 2021-09-25
  • 2022-01-20
  • 2021-08-29
  • 2021-06-10
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2021-06-24
  • 2022-01-08
  • 2021-09-25
  • 2022-01-04
  • 2021-10-22
  • 2021-06-20
  • 2021-07-26
相关资源
相似解决方案