Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by syphilis (Archbishop)
on Jun 12, 2013 at 02:59 UTC ( [id://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.

Cheers,
Rob
  • 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found