Skip to content
Advertisement

How can i check a PHP MD5 hash with number type in nodejs server

I’m trying to generate a MD5 hash code in NodeJS and compare it with a php-generated MD5 hash code with number type ex: md5(10). NodeJS does not seem to have a way to generate a MD5 hash with number type only – only String, Buffer, Array or Uint8Array types are supported.

I tried storing the number into a buffer, or a binary list but I did not manage to match the php-generated hash :

JavaScript

What exactly MD5 in php do with the data type ?
Which data form should i use to get the same result ?

Advertisement

Answer

The md5 function in PHP calculates the hash of a string, so in your example it’s actually calculating the hash of “10”.

To do this in Node.js should be quite simple:

JavaScript

We get the same result in Node.js as in PHP, e.g.

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