---
title: "python小例子之7 -- 生成md5串"
author: "weistar"
date: "2014-03-19T14:40:03Z"
tags: []
categories: ["编程语言"]
slug: "python-7-md5"
draft: true
lastmod: "2014-03-18T17:12:03Z"
id: 2032939
url: "https://weistar.iteye.com/blog/2032939"
---

文章源自：http://bluecrystal.iteye.com/blog/131980

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

        主题：生成md5串  
        环境： winxp pro + sp2 + python2.5  
        备注： 请注意，凡是在源代码文件中使用了中文字符，请最好保存为utf-8格式  
        代码：

```
    # tmd5.py   
    import md5  
    import hashlib   
      
    src = 'this is a test.'   
    m1 = md5.new()   
    m1.update(src)   
    dest1 = m1.hexdigest()   
      
    m2 = hashlib.md5()   
    m2.update(src)   
    dest2 = m2.hexdigest()   
      
    print 'source string: ', src   
    print 'destination string1: ', dest1   
    print 'destination string2: ', dest2   

```