[英]python hashlib.md5 escape characters
Following snippet presents basic usage of python hashlib.md5
(in py2.7). 以下片段介绍了python hashlib.md5
基本用法(在py2.7中)。
>>> import hashlib
>>> m = hashlib.md5()
>>> m.update('phrase')
>>> m.digest()
'8Z\xa58^\x83\xef\xc5\xd8<u\x88\xee_\xb7\xe8'
>>> type(m.digest())
<type 'str'>
I've got two questions: 我有两个问题:
385aa5385e83efc5d83c7588ee5fb7e8
? python不返回像385aa5385e83efc5d83c7588ee5fb7e8
这样的简单哈希的原因是什么? What is this escaped hex representation used for? 这个转义的十六进制表示法是做什么用的? For 1.: Just use m.hexdigest()
. 对于1 .:只需使用m.hexdigest()
。
See here for docs: http://docs.python.org/2/library/hashlib.html#hashlib.hash.hexdigest 请参阅此处以获取文档: http : //docs.python.org/2/library/hashlib.html#hashlib.hash.hexdigest
You are looking at the binary representation of the hash digest. 您正在查看哈希摘要的二进制表示形式 。 What you want is the hex digest, produced by hash.hexdigest()
: 您想要的是由hash.hexdigest()
生成的十六进制摘要:
>>> import hashlib
>>> m = hashlib.md5()
>>> m.update('phrase')
>>> m.hexdigest()
'385aa5385e83efc5d83c7588ee5fb7e8'
Python gives you access to both the original binary value and the hexadecimal representation. Python使您可以访问原始二进制值和十六进制表示形式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.