0

I have to convert this function from php to javascript:

<?php
   
   $hashbytes = mb_convert_encoding($hashtr, "ISO-8859-9");
   $hash = base64_encode ( sha1 ( $hashbytes, true ) );

And i tried this :

   function sha1(data) {
       return crypto.createHash("sha1").update(data, "binary").digest("hex");
   }

   hash = Buffer.from( sha1 ( hashtr, true )).toString('base64')
   

But when i compare that results they are not equals. Where i do mistake ?

ayya
  • 71
  • 5
  • what is the `data` encoding? In php it is `ISO-8859-9`, I suppose it is `utf-8` in nodejs – Manuel Spigolon Dec 28 '20 at 17:04
  • @ManuelSpigolon sadly there are some differences as answered here : https://stackoverflow.com/questions/26118570/utf-8-and-iso-8859-9 – ayya Dec 28 '20 at 17:12
  • This package [windows-1254](https://www.npmjs.com/package/windows-1254) should help you. Notice that iso-8859-9 is an alias per [windows-1254](https://encoding.spec.whatwg.org/#names-and-labels) – Manuel Spigolon Dec 28 '20 at 17:25

0 Answers0