0

I need to write a md5 hash in python from php and have been suck trying to make the dates give the right md5 hash. Both languages print the exact same date but if that date is hashed the hash is different.

** md5 hash needs to match the original php hash (changes need to be made to python not php)

md5.py

import hashlib, datetime

timestamp = datetime.datetime.now() - datetime.timedelta(hours=6)
timestamp1 = timestamp.strftime("%Y-%m-%d %H:%M:%S")

print(timestamp1)


md5_digest = hashlib.md5(timestamp1.encode()).hexdigest()

print (md5_digest)

md5.php

<?php

$strDatetime = date("Y-m-d H:i:s");

function get_md5_hash($strDatetime) {
return md5(strtotime($strDatetime));
}

print("$strDatetime");
print get_md5_hash("$strDatetime", "$strAuthWindow", "$strSalt");

?>

This is the result I get:

2018-04-18 13:24:01 36bae8f24429309f147f3bd6d8a1e0c9

2018-04-18 13:24:01 0eab3b000e3d831a57f9e7b77f136900

Alex Winkler
  • 469
  • 4
  • 25

1 Answers1

2

In Python you're hashing the timestamp string. In PHP you're calling strtotime() and converting the string to an integer UNIX timestamp. Remove that call.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Thanks for the response. I forgot to be clear that I need the Python code to match the PHP hash, not the other way around. – Alex Winkler Apr 18 '18 at 17:36