Skip to content
Advertisement

Sha256 checksum difference between Java vs Linux

Am writing a application which calculate the checksum of file before sending it to downstream. At downstream application, linux shell script are used to process the files. It is noticed that checksum calculated from Java application doesn’t matches that calculated using Linux command ‘sha256sum’.

Below is code snippet in JAVA:

JavaScript

Using java api i get checksum value as :

JavaScript

but when the checksum is calculated for for same file using Linux command ‘sha256sum <file>‘ then it gives

JavaScript

Below is what the file contain. You can create file with below content. Am using abc.txt. It has newlines.

JavaScript

Can some suggest what’s going wrong here? File is not corrupted. Contents are identical at source and destination.

Advertisement

Answer

I was able to get both the digests from two different files. See their hexdumps:

d05a9724479af8a7a20f7acff3629b0dd8aaa447ec821b4b31708bc43eb99841:

JavaScript

37f865eb2a3956e3f903eaaf92f0459143cf9b9699a7d1d6bc91bfc89ad5eb8c:

JavaScript

The difference is end of line type, *nix versus MSWin.

The size of the files is not the same, it’s 15 versus 17 bytes.

Java gives the same results.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement