Python的sha1加密和MD5加密相似。
# encoding: utf-8import hashlibsha1 = hashlib.sha1()data = 'test'sha1.update(data.encode('utf-8'))sha1_data = sha1.hexdigest()print(sha1_data)
加密结果:
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
# encoding: utf-8import hashlibdef to_sha1(part): sha1 = hashlib.sha1() sha1.update(part.encode()) return sha1.hexdigest()if __name__ == '__main__': print("SHA1加密结果:", to_sha1('test'))
SHA1加密结果: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3