MD5 hash discrepancy between Python and PHP? MD5 hash discrepancy between Python and PHP? python python

MD5 hash discrepancy between Python and PHP?


I would rather assume that the base64 implementations differ.

EDIT

PHP:

php -r 'var_dump(base64_encode(str_repeat("x", 10)));'string(16) "eHh4eHh4eHh4eA=="

Python (Note the trailing newline):

>>> ("x" * 10).encode('base64')'eHh4eHh4eHh4eA==\n'


The problem seems to be that your base-64-encoding the file data, changing the structure of the binary data, in php I belive that it does not base_64 encode the file.

Give this a go:

def md5_file(filename):    //MD5 Object    crc = hashlib.md5()    //File Pointer Object    fp = open(filename, 'rb')    //Loop the File to update the hash checksum    for i in fp:        crc.update(i)    //Close the resource    fp.close()    //Return the hash    return crc.hexdigest()

and within PHP use md5_file and see if that works accordingly.

python taken from: http://www.php2python.com/wiki/function.md5-file/