I'm attempting to re-create this bit of C# code, but in Javascript, but the results are not coming out the same at all. The goal is to take a buffer of a known size, get an MD5 hash of it, then convert the MD5 hash to a string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value, then remove all the -
's in the string. But... do it in Javascript.
C# Code
internal static string ComputeHash(byte[] buffer)
{
HashAlgorithm MD5 = new MD5CryptoServiceProvider();
return BitConverter.ToString(MD5.ComputeHash(buffer)).Replace("-", string.Empty);
}
My Javascript
const buffer = new ArrayBuffer(1024);
const md5 = require('md5'); // https://www.npmjs.com/package/md5
const hash = md5(buffer); // 441018525208457705bf09a8ee3c1093
const hexString = hash.toString('hex');
console.log(hexString); // not correct
I appreciate any and all pointers and tips, even minor suggestions on how to improve the actual question itself. Thanks for looking!
SOLVED: This package did it correctly for me... Sorry for the (semi)-duplicate answer. https://www.npmjs.com/package/md5-hex