import hashlib # md5 m = hashlib.md5() m.update(b"Hello") print(m.digest()) # 返回的是二進制的hash值 m.update(b"world") print(m.hexdigest()) # 返回的是十六進制的hash值 # sha1 s1 = hashlib.sha1() s1.update("測試".encode("utf-8")) s1.hexdigest() # sha256 s256 = hashlib.sha256() s256.update("測試".encode("utf-8")) s256.hexdigest() # sha512 s512 = hashlib.sha256() s512.update("測試".encode("utf-8")) s512.hexdigest()