`
bluecrystal
  • 浏览: 265590 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

python小例子之7 -- 生成md5串

阅读更多
主题: 生成md5串
 环境: winxp pro + sp2 + python2.5
备注: 请注意,凡是在源代码文件中使用了中文字符,请最好保存为utf-8格式
代码:
python 代码
  1. # tmd5.py   
  2. import md5  
  3. import hashlib   
  4.   
  5. src = 'this is a test.'   
  6. m1 = md5.new()   
  7. m1.update(src)   
  8. dest1 = m1.hexdigest()   
  9.   
  10. m2 = hashlib.md5()   
  11. m2.update(src)   
  12. dest2 = m2.hexdigest()   
  13.   
  14. print 'source string: ', src   
  15. print 'destination string1: ', dest1   
  16. print 'destination string2: ', dest2   
测试:保存为文件,直接执行即可
分享到:
评论
2 楼 i-david 2012-08-17  
python 2.7 python 3.1 md5加密串,怎么弄
1 楼 henyue 2008-07-25  
为什么我的报错啊?

Traceback (most recent call last):
  File "/home/henyue/workspace/MyPython/src/md5.py", line 2, in <module>
    import md5
  File "/home/henyue/workspace/MyPython/src/md5.py", line 6, in <module>
    m1 = md5.new()
AttributeError: 'module' object has no attribute 'new'

相关推荐

Global site tag (gtag.js) - Google Analytics