Skip to content
Advertisement

hash in JS == hash in PHP

I need to make a hash with JS and PHP but I need them to both work out to be the same hash.
I am just wondering what the best idea would be to go about it. it needs to be secure, but its not hashing sensitive data so doesn’t need a huge amount of security around it.

could anyone give me some examples

Thank you.

Advertisement

Answer

You could use MD5: the php and the JS solution should work out to be the same given the same string input. http://pajhome.org.uk/crypt/md5/ has a list of hash implementations in javascript, and PHP implementations of md5 are documented here, and both have examples at hand.

You’ll need to be careful that you use the exact same input to both functions, but otherwise it shouldn’t be too painful.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement