Digest:: - Modules that calculate message digests |
Digest:: - Modules that calculate message digests
$md2 = Digest->MD2; $md5 = Digest->MD5;
$sha1 = Digest->SHA1; $sha1 = Digest->new("SHA-1");
$hmac = Digest->HMAC_MD5($key);
The Digest::
modules calculate digests, also called ``fingerprints''
or ``hashes'', of some data, called a message. The digest is (usually)
some small/fixed size string. The actual size of the digest depend of
the algorithm used. The message is simply a sequence of arbitrary
bytes.
An important property of the digest algorithms is that the digest is likely to change if the message change in some way. Another property is that digest functions are one-way functions, i.e. it should be hard to find a message that correspond to some given digest. Algorithms differ in how ``likely'' and how ``hard'', as well as how efficient they are to compute.
All Digest::
modules provide the same programming interface. A
functional interface for simple use, as well as an object oriented
interface that can handle messages of arbitrary length and which can
read files directly.
The digest can be delivered in three formats:
The functional interface is simply importable functions with the same name as the algorithm. The functions take the message as argument and return the digest. Example:
use Digest::MD5 qw(md5); $digest = md5($message);
There are also versions of the functions with ``_hex'' or ``_base64'' appended to the name, which returns the digest in the indicated form.
The following methods are available for all Digest::
modules:
XXX($arg,...)
new($arg,...)
The two first forms are simply syntactic sugar which automatically load the right module on first use. The second form allow you to use algorithm names which contains letters which are not legal perl identifiers, e.g. ``SHA-1''.
If new()
is called as an instance method (i.e. $ctx->new) it will just
reset the state the object to the state of a newly created object. No
new object is created in this case, and the return value is the
reference to the object (i.e. $ctx).
add($data,...)
addfile($io_handle)
Note that the digest
operation is effectively a destructive,
read-once operation. Once it has been performed, the $ctx object is
automatically reset
and can be used to calculate another digest
value. Call $ctx->clone->digest if you want to calculate the digest
without reseting the digest state.
the Digest::MD5 manpage, the Digest::SHA1 manpage, the Digest::HMAC manpage, the Digest::MD2 manpage
Gisle Aas <gisle@aas.no>
The Digest::
interface is based on the interface originally
developed by Neil Winton for his MD5
module.
Digest:: - Modules that calculate message digests |