brix / crypto-js

JavaScript library of crypto standards.
Other
15.74k stars 2.38k forks source link

Why does it differ CyrptoJS.MD5 than online MD5 converter websites ? #297

Open halilozanyilmaz opened 4 years ago

halilozanyilmaz commented 4 years ago

Hi, I am using CyrptoJS in postman application. Below is the string that I convert MD5.

<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

This is the MD5 result of CryptoJS: c1109e58560c1b1ddb3cd4e325cf775b

This is the MD5 result of onlinemd5.com: D17BBCA15C9C21E2D8C8DFAD08177213

This is the MD5 result of passwordsgenerator.net D17BBCA15C9C21E2D8C8DFAD08177213

And I need to use the MD5 value in amazon web services, and amazon web services is expecting the same result with the above websites.

The only website that gives the same result with CryptoJS is md5hashgenerator.com

I realized that this can be caused because of "newline". This newline character is treated differently on those websites.

I want CryptoJS to treat new lines as same as amazon, or onlinemd5.com, or passwordsgenerator.net. How to get same result with CryptoJS.MD5 function ?

AlttiRi commented 4 years ago
import CryptoES from "crypto-es";
import CryptoJS from "crypto-js";

console.log(CryptoES.MD5(`<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`).toString());

console.log(CryptoJS.MD5(`<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`).toString());
d17bbca15c9c21e2d8c8dfad08177213
d17bbca15c9c21e2d8c8dfad08177213
halilozanyilmaz commented 4 years ago

Hi, I am getting this result on POSTMAN application,

so possibly somehow the text is treated differently, do you think that CryptoJS has a function to fix how newlines are treated ? Or is this problem completely related to POSTMAN application ?

Below are the screenshots:

image

Here the code:

image

AlttiRi commented 4 years ago

Debug this.

const reference = `<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`;

console.log(pm.request.body.raw === reference);
console.log(pm.request.body.raw);
halilozanyilmaz commented 4 years ago

thank you, postman adds ↵ character, Removing it helped.