Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Digest::SHA gives different values for unix/windows

by syphilis (Chancellor)
on Jun 12, 2013 at 02:59 UTC ( #1038377=note: print w/ replies, xml ) Need Help??

in reply to Digest::SHA gives different values for unix/windows

$sha1->addfile($data, "p");

I'm not sure that you'd want to use "p" with binary files. (I haven't checked, but I'm thinking it might be applicable only for text files.)
Try specifying "b" - and if that fixes things then you've found the problem.
Otherwise, it's probably as Jim said.


Comment on Re: Digest::SHA gives different values for unix/windows
Replies are listed 'Best First'.
Re^2: Digest::SHA gives different values for unix/windows
by rmahin (Scribe) on Jun 12, 2013 at 06:06 UTC
    Yeah I tried that too. Even tried a "pb" (not even sure if you can do that or not, the doc is unfortunately not very specific, but figured portable binary files would have been good) and there was absolutely no difference in the resulting value using any of the modes or none at all. :/

      I saw your comment above that the problem seems to be in the transferring of the file. In addition to that, I just wanted to confirm what syphilis suggested: After transfer you should be using the "b" mode. From the Digest::SHA docs (emphasis mine):

      The "p" mode is handy since it ensures that the digest value of $filename will be the same when computed on different operating systems. It accomplishes this by internally translating all newlines in text files to UNIX format before calculating the digest. Binary files are read in raw mode with no translation whatsoever.

      The name "portable" is a bit confusing here.

        I'm dumbfounded by the "feature" of a mode argument to the Digest::SHA::addfile() method. Why does a module whose simple purpose is to compute the message digest of a block of data permit monkeying with that block of data? It violates the principle of separation of concerns. Look at the trouble it caused rmahin.

        There's no such feature in Digest::MD5.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038377]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-11-26 12:57 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (698 votes), past polls