in reply to Re: Using MD5 and the theory behind it
in thread Using MD5 and the theory behind it

You say that you 'compare its MD5' value to the values in a table. How do you get an MD5 value for a file? What exactly do you mean by this process (I believe that this process is very similar to the one that I am attempting). Thanks for the help!
  • Comment on Re: Re: Using MD5 and the theory behind it

Replies are listed 'Best First'.
Re: Re: Re: Using MD5 and the theory behind it
by arturo (Vicar) on Jan 10, 2001 at 06:56 UTC

    For reasonable-sized files (ones that fit comfortably in system memory): load the file's contents into a perl scalar, say $foo. Then $fingerprint = md5($foo);

    If you look through the documentation you have for it, you'll get some advice on other methods; e.g. (the object-oriented versions) :

    my $file ="/file/to/hash"; my $md5 = Digest::MD5->new(); $md5->addfile($file); $md5->add("seekrit passwerd"); # not the best choice for one, but ... my $digest = $md5->digest;

    I got this straight out of the docs, more or less. HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      Small correction:
      my $file = "/file/to/hash"; my $md5 = Digest::MD5->new(); open(MD5, $file) || die "Unable to open file: $!\n"; binmode(MD5); $md5->addfile(*MD5); $md5->add("seekrit passwerd"); # tee hee my $digest = $md5->digest;
      Your original code will not work with the latest Digest::MD5, producing the error "Not a valid filehandle." I know this because I'm currently writing a utility script that uses MD5 to verify downloaded files (for the Slackware distrib, actually) and I tried it your way to no avail. =)

      'kaboo