Verify that files aren't modified
I'd like to verify that a b开发者_运维问答unch of files (ten files or so) are unchanged. I thought it create a CRC/MD5 hash lists for these files and compare them with realtime hashes.
- What's more recommended? CRC or MD5?
- What is the right way to do it with Python?
Thanks.
CRC is simpler and faster, but only really designed to detect unintentional changes. MD5 is more secure.
Both are built into the Python Standard Library, check out hashlib for details.
http://docs.python.org/library/hashlib.html
Also worth considering is SHA1 which is far more secure, but it really depend on why they may have been modified. CRC is good against random errors such as corruption in transit. MD5 and SHA1 are o do with intentional changes. SHA1 is better, but MD5 may be quicker.
精彩评论