Python版PHP内置的MD5()函数

作者:matrix 被围观: 1,986 次 发布时间:2014-09-01 分类:Python | 7 条评论 »

这是一个创建于 3524 天前的主题,其中的信息可能已经有所发展或是发生改变。

初玩Python很不习惯那个md5函数。还好有人分享了相关代码,非常感谢。

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("welcome").hexdigest()
# pre-2.5, removed in Python 3
import md5
md5.md5("welcome").hexdigest()

参考:Python 实现PHP内置MD5函数方法

其他文章:
本文固定链接:https://www.hhtjim.com/python-version-of-phps-built-in-md5-function.html
matrix
本文章由 matrix 于2014年09月01日发布在Python分类下,目前没有通告,你可以至底部留下评论。
转载请注明:Python版PHP内置的MD5()函数-HHTjim'S 部落格
关键字:, , , ,

有7 条评论 »

  1. 晨曦 晨曦 2014-10-17 13:45:05 +0800#5

    py这个好耳熟的感觉,想不起来了突然=_=

  2. tennfy tennfy 2014-9-26 20:56:05 +0800#4

    前段时间也在学习python,很有意思

  3. 只看不评论,不是好孩子,哈哈!

    • Matrix Matrix Moderator 2014-9-3 16:50:01 +0800

      你肯定就是好孩子了 😆

  4. Small Desert Small Desert 2014-9-1 18:55:03 +0800#2

    最近开始研究Python了吗?

    • Matrix Matrix Moderator 2014-9-1 21:38:05 +0800

      只是了解一些python的代码

  5. 快乐淘 快乐淘 2014-9-1 14:13:02 +0800#1

    非常有用,要收藏着。。。。。

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!