I'm implementing a server in node.js
which will accept a file(Multipart request) from the client along with a checksum(CRC32
), verify that the received file's integrity using the checksum and then respond, depending on the response of the CRC checksum.
My problem is occurring when I calculate the CRC32 checksums. Both the client(Java
) and the server calculate different CRC32 checksums for the same file.
In Java, my code to calculate the checksum is
CheckedInputStream checkedInputStream = new CheckedInputStream(new FileInputStream(new File(filepath)), new CRC32());
final byte[] buf = new byte[128];
while (checkedInputStream.read(buf) >= 0) {
//No need to do anything here
}
String checksum = Long.toHexString(checkedInputStream.getChecksum().getValue());
In node.js
, after saving my file, I do
var crc = require('crc')
var crc32 = crc.crc32(fs.readFileSync('image.jpg')).toString(16);
However, both of them are giving me different checksums. This is when the both the server and client are running on my local system and are checking the same file.
Any idea what I'm doing incorrectly here?
Aucun commentaire:
Enregistrer un commentaire