Alt-Digest-MD5-OpenSSL
view release on metacpan or search on metacpan
lib/Digest/MD5.pm view on Meta::CPAN
163164165166167168169170171172173174175176177178179180181182183message we calculate the digest
for
. The
return
value is the
$md5
object itself.
The addfile() method will croak()
if
it fails reading data
for
some
reason. If it croaks it is unpredictable what the state of the
$md5
object will be in. The addfile() method might have been able to
read
the file partially
before
it failed. It is probably wise to discard
or
reset
the
$md5
object
if
this occurs.
In most cases you want to make sure that the
$io_handle
is in
C<
binmode
>
before
you pass it as argument to the addfile() method.
=item $md5->add_bits($data, $nbits)
=item $md5->add_bits($bitstring)
Since the MD5 algorithm is byte oriented you might only add bits as
multiples of 8, so you probably want to just use add() instead. The
add_bits() method is provided for compatibility with other digest
implementations. See L<Digest> for description of the arguments
that add_bits() take.
lib/Digest/MD5.pm view on Meta::CPAN
250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285With OO style, you can break the message arbitrarily. This means that we
are
no
longer limited to have space
for
the whole message in memory, i.e.
we can handle messages of any size.
This is useful
when
calculating checksum
for
files:
my
$filename
=
shift
||
"/etc/passwd"
;
open
(
my
$fh
,
'<'
,
$filename
) or
die
"Can't open '$filename': $!"
;
binmode
(
$fh
);
my
$md5
= Digest::MD5->new;
while
(<
$fh
>) {
$md5
->add(
$_
);
}
close
(
$fh
);
$md5
->b64digest,
" $filename\n"
;
the file:
my
$filename
=
shift
||
"/etc/passwd"
;
open
(
my
$fh
,
'<'
,
$filename
) or
die
"Can't open '$filename': $!"
;
binmode
(
$fh
);
Digest::MD5->new->addfile(
$fh
)->hexdigest,
" $filename\n"
;
Since the MD5 algorithm is only
defined
for
strings of bytes, it can not be
used on strings that contains chars
with
ordinal number above 255 (Unicode
strings). The MD5 functions and methods will croak
if
you
try
to feed them
such input data:
t/original/files.t view on Meta::CPAN
150151152153154155156157158159160161162163164165
$digest
;
}
sub
cat_file
{
my
(
$file
) =
@_
;
local
$/;
# slurp
open
(FILE,
$file
) or
die
"Can't open $file: $!"
;
# For PerlIO in case of UTF-8 locales.
eval
'binmode(FILE, ":bytes")'
if
$] >= 5.008;
my
$tmp
= <FILE>;
close
(FILE);
$tmp
;
}
( run in 0.428 second using v1.01-cache-2.11-cpan-3fc6ead820a )