使用python计算md5

Posted by 4Aiur on 04/06/2010 in Python |

使用python计算md5

#!/usr/bin/env python3
import os
import hashlib

# Use hashlib module
file = open("foo", "rb")
content = file.read()
file.close()
result = hashlib.md5()
result.update(content)
md5sum = result.hexdigest()
print(md5sum)

# Use OS command
result = os.popen("md5sum foo").readline()
md5sum = result.split()[0]
print(md5sum)

Tags:

Copyright © 2010-2024 4Aiur All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.