废话少说 直接上代码,方便由PHP转到python的同学们用:
import hashlib
def md5 (s, raw_output = False):
res = hashlib.md5 (s)
if raw_output:
return res.digest ()
return res.hexdigest ()
如果是python2.5 如下:
# Python 2.5+
import hashlib
hashlib.md5("Hello,Yangqijun").hexdigest()
# pre-2.5, removed in Python 3
import md5
md5.md5("Hello,Yangqijun").hexdigest()