0

I'm newbie to node js , I am using node version v10.21.0 with firebase functions, flutter 1.20.3 (dart 2.9.2)

I am generating the SHA256 hash for the image file in dart then , uploading the a zipped image files into the storage. Dart code is as below for generating image hash:

Future<String> generateImageHash(File file) async {
  var image_bytes = file.readAsBytesSync().toString();
  var bytes = utf8.encode(image_bytes); // data being hashed
  String digest = sha256.convert(bytes).toString();
  return digest;
}

When downloading the zipped file from cloud storage using firebase functions I am unzipping the file , storing them in temp directory and then generating the SHA256 hash for the image files as shown below :

fs.readFile(path.join(dir, file), (err, fd) => {
if (!err) {
     crypto.createHash('sha256').update(fd).digest('hex');
   }
}

However the SHA256 hash is not same as that generated from dart code.However if I download the zip file from cloud storage in dart code and generate the hash for the files it matches the SHA256 hash generated before uploading

What could be the issue ? I have tried with previous SO posts with no luck.

day_dreamer
  • 824
  • 3
  • 13
  • 33

1 Answers1

0

I have found that the issue is in my dart code not in the node js as I was thinking This SO post helped

day_dreamer
  • 824
  • 3
  • 13
  • 33