相关疑难解决方法(0)

将hexdigest()的结果与字符串进行比较

我有一个生成的MD5哈希,我想将其与字符串中的另一个MD5哈希进行比较.下面的陈述是错误的,即使它们在打印时看起来一样,应该是真的.

hashlib.md5("foo").hexdigest() == "acbd18db4cc2f85cedef654fccc4a4d8"
Run Code Online (Sandbox Code Playgroud)

谷歌告诉我,我应该对结果进行编码hexdigest(),因为它不会返回字符串.但是,下面的代码似乎也不起作用.

hashlib.md5("foo").hexdigest().encode("utf-8") == "foo".encode("utf-8")
Run Code Online (Sandbox Code Playgroud)

python python-2.x string-comparison hashlib

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

hashlib ×1

python ×1

python-2.x ×1

string-comparison ×1