1. import M2Crypto  
  2.  
  3. def md5(buf):  
  4.     b = M2Crypto.EVP.MessageDigest('md5')  
  5.     b.update(buf)  
  6.     c = b.digest()  
  7.     s = '' 
  8.     for i in c: s = s + '%02x' % ord(i)  
  9.     return s  
  10.  
  11. print md5('123456')