md5_bin#
One-shot MD5 digest, returned as 16 raw bytes.
Σύνοψη#
use Digest::MD5 qw(md5);
my $bin = md5($data); # 16 bytes
my $bin = md5($a, $b, $c); # md5($a.$b.$c)
Τι επιστρέφεται#
A 16-byte Perl string holding the raw MD5 digest. All arguments are concatenated (in order) and the result is hashed, so md5("a", "b", "c") is the same as md5("abc"). The function does not allocate an object; it runs through a stack-local context, which makes it the cheapest way to hash something you already hold in memory.
Use md5_hex or md5_base64 when you need a printable form.
Παραδείγματα#
Digest a string to raw bytes:
use Digest::MD5 qw(md5);
my $bin = md5("hello world"); # 16 bytes
printf "%v02x\n", $bin;
## 5e.b6.3b.bb.e0.1e.ee.d0.93.cb.22.bb.8f.5a.cd.c3
Concatenation is implicit:
my $a = md5("foo", "bar");
my $b = md5("foobar");
## $a eq $b
Pack into a binary record:
my $blob = pack("N a16", length($payload), md5($payload));
Οριακές περιπτώσεις#
md5()with no arguments returns the MD5 of the empty string (d41d8cd98f00b204e9800998ecf8427ein hex).Wide-character arguments (code points above
U+00FF) croak withWide character in subroutine entry. Encode first:md5(encode_utf8($str)).Called as a class or instance method (e.g.
Digest::MD5->md5(...)), it warns about probable misuse but still returns a digest based on all arguments, including the invocant. Prefer the plain function call.
Διαφορές από το upstream#
Fully compatible with upstream Digest::MD5 2.58.
Δείτε επίσης#
md5_hex- same digest, as 32 lowercase hex charactersmd5_base64- same digest, base64-encodeddigest- OO form; reuse one context across many inputsaddfile- for data too large to hold in memory at once