in reply to MD5 Peculiarities
Here is how I would tackle the problem.
I can see that the output of Digest::MD5 in OO mode is incorrect.
By comparing with some independent programs, you realize that the output of md5sum and mysql is the same as the functional interface of Digest::MD5
$ perl -e 'use Digest::MD5; print Digest::MD5->new->md5_hex("foobarbaz +") ,$/' e05e07ceb87ddb19ccba8a51a57ac120 $ perl -e 'use Digest::MD5 qw(md5_hex); print md5_hex("foobarbaz"),$/' 6df23dc03f9b54cc38a0fc1483df6e21 $ echo -n foobarbaz | md5sum 6df23dc03f9b54cc38a0fc1483df6e21 *- $ mysql -e "select md5('foobarbaz')" +----------------------------------+ | md5('foobarbaz') | +----------------------------------+ | 6df23dc03f9b54cc38a0fc1483df6e21 | +----------------------------------+
Now, let's apply a constitutional principle, according tro which, everybody is innocent until proved guilty. So I would say that the OO interface is innocent, and look at the docs. They say that this is the regular format of the OO interface.
use Digest::MD5; $md5 = Digest::MD5->new; $md5->add('foo', 'bar'); $md5->add('baz'); $digest = $md5->hexdigest;
This is different from what you have done. Let's try it the "official" way.
sub create_checksum { my $self = shift; my $data = shift; my $foo = $$data; my $ctx = Digest::MD5->new; $ctx->add($foo); my $cs = $ctx->hexdigest(); return $cs; }
This works fine. Proof of concept:
$ perl -e 'use Digest::MD5; my $x= Digest::MD5->new; $x->add("foobarba +z"); print $x->hexdigest,$/' 6df23dc03f9b54cc38a0fc1483df6e21
The OO interface is innocent.
Your implementation is guilty. :)
_ _ _ _ (_|| | |(_|>< _|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: MD5 Peculiarities
by isotope (Deacon) on Jun 22, 2003 at 15:03 UTC | |
|
Re: Re: MD5 Peculiarities
by skazat (Chaplain) on Jun 23, 2003 at 04:53 UTC |