perl - Why are MD5 hashes for the same data different on Linux and Windows? -


here's workflow.

  1. client uploads xml file , checksum md5 file our ftp.
  2. the perl server copies file ftp server.
  3. the perl server runs own md5 check on xml file , compares value in md5 file.

the 2 md5 hashes never match. but, when copy xml file windows machine , run same perl script running in windows, same answer md5 file.

can tell me what’s going on?

here’s script using compute md5 hash.

use warnings; use strict; use digest::md5; $fname = "marketpricepoint_2013_07_16_1500.xml"; open (my $fh, '<', $fname) or die "can't open '$fname': $!"; binmode ($fh); $hash = digest::md5->new->addfile($fh)->hexdigest; print $hash; 

ascii mode common default ftp servers performs silent translation of line endings. if transferring in binary mode not option, consider normalizing line endings, in following.

use strict; use warnings;  use digest::md5;  $fname = "marketpricepoint_2013_07_16_1500.xml"; open (my $fh, '<', $fname) or die "$0: open $fname: $!"; binmode ($fh) or die "$0: binmode: $!";;  (my $data = { local $/; <$fh> }) =~ s/\r\n/\n/g;  $hash = digest::md5->new->add($data)->hexdigest; print $hash, "\n"; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -