Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
MD5 Checksum differes from browser to Node js API

I am trying to perform a checksum on a file with javascript. I'm using a FileReader and using CryptoJS with the .MD5 method as well as the CryptoJS.enc.Hex encoding.

The checksums differ from the front end (above) and on the back end, where I am getting it from ExpressFIleUpload and also generated my own with the crypto module via crypto.createHash('md5') and getting a digest via hash.digest('hex'); and out of those two, (my own and ExpressFileUpload) they too, differ..

what is going on..?

        let img = document.createElement('img');
        img.file = data;

        let reader = new FileReader();
        reader.onload = (function (someelement) {
            return function (e) {
                let md5 = CryptoJS.MD5(e.target.result);
                let str = md5.toString(CryptoJS.enc.Hex);
                console.log('str', str); // will give one random md5
            };
        })(img);

        reader.readAsBinaryString(data);

then on the server using https://www.npmjs.com/package/express-fileupload

export async function(req, res, next) {
  console.log(req.files.file.md5) // some other md5
  
  const hash = crypto.createHash('md5');
  let buff = Buffer.from(req.files.file.data, "base64").toString('utf-8');

  // edit, this actually DOES come to the same if I remove 
  // .toString('utf-8')
  // as the req.files.file.md5

  hash.update(buff);

  let str = hash.digest("hex");
  console.log('other hash', str); // and some third completely different md5
}

can someone please explain what I am doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Did you encode the e.target.result to UTF-8 in your front-end? I had kind of like the same problem, but then I realized, that I'd used the wrong encoding.

Try to encode your Plain String into utf-8 and hash it after that.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda