如何在python3中转换php md5(sha1(time()))?

问题描述

我是 Python 新手..

通常我在 PHP md5(sha1(time())) 中执行此操作并将其转换为:017df9435b048f86ac28a274543ac46df5e20e0ecff32123a58287

现在如何在python3中做到这一点?

我尝试导入 hashlib print(hashlib.md5(int(round(time.time() * 1)))) 但效果不佳。

有人可以帮我吗?提前致谢。

解决方法

它不返回与

相同的值
md5(sha1(time()))

同时因为 php 函数 md5 和 sha1 返回了一些因为与 python3 函数 hashlib.sha1 hashlib.md5 不同的东西,但是下面的代码可能是你想要的:

import hashlib,time
print(hashlib.md5(hashlib.sha1(str(int(round(time.time()))).encode()).hexdigest().encode()).hexdigest())