react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

How to calculate identical hashes in React Native and Node?

Open joebernard opened this issue 6 years ago • 4 comments

I'm using hash to generate checksums for files before I upload them to AWS S3.

RNFS.hash(localUrl, "md5")

This seems to work great. Once the file has been uploaded, I need to verify the checksum for the file using Node 10.x (Lambda). I can't seem to get the same checksum using other libraries. For example, with Node's crypto.createHash:

const file = await s3
          .getObject({
            Bucket,
            Key
          }).promise()

crypto
    .createHash("md5")
    .update(file.Body)
    .digest("hex");

The generated hash does not match what was produced by react-native-fs. How do I generate a hash in Node identical to what is produced by react-native-fs for the same file?

joebernard avatar Sep 10 '19 00:09 joebernard

Hi @joebernard have you find any solution for the same.I am also facing same issue in IOS md5 hash is differ from aws md5 hash.

prashantm8 avatar May 12 '21 09:05 prashantm8

@prashantm8 No I was never able to find a good solution for this. Please post if you discover one.

joebernard avatar May 12 '21 11:05 joebernard

@prashantm8 No I was never able to find a good solution for this. Please post if you discover one.

Then could you please tell me any work around. I am trying to send file on aws with presigned url. Since its a private bucket we have tocalculate checksum. But this checksum is not matching with aws checksum only on Ios.

prashantm8 avatar May 16 '21 18:05 prashantm8

react-native-fs hash method seems to work correctly. There might be a problem with the way you are picking the file in React Native.

augini avatar Feb 24 '22 06:02 augini