OpenBSD::md5(3p)

NAME
OpenBSD::md5 - simple interface to md5 and sha256 digests

SYNOPSIS
    use OpenBSD::md5;

    my $md5 = OpenBSD::md5->new($filename);
    $k->{$md5->key} = $filename;

    my $ck2 = $md5->new($filename2);

    if ($ck2->equals(md5)) {
         ...
    }

    print $md5->stringize # provides an hex representation

    my $ck3 = OpenBSD::sha->new($filename);
    !$ck3->equals($ck2); # comparing is okay, but will never match
    my $s = $ck3->stringize; # base64 representation

    my $ck4 = $s->fromstring; # decodes both base64 and hex

DESCRIPTION
"OpenBSD::md5" provides an object-oriented interface to cryptographic hashing facilities for use in the ports tree.

In particular, it provides an abstraction to build crypto hashes from files, convert from and to text, and compare two checksums while keeping the user from making low-level decisions.

There are two classes, "OpenBSD::md5" and "OpenBSD::sha" which provide the same facilities, respectively for md5 and sha256 digests.

The module itself is called "OpenBSD::md5" for historical reasons. Support for md5 digests is there for legacy reasons, all new code should produce and write sha256 digests only.

$o = $class->new($filename)
    create a new digest object from the contents of a file.

$o = $class->fromstring($string)
    create a new digest object from a string representation.

$o2 = $o->new($filename) / $o->fromstring($string)
    create a new digest object $o2 of the same type as $o. This can be used to compare a file against an existing digest, which may well be of md5 type in very old packages. Even though the use of md5 is deprecated, checking md5 checksums is still slightly better than nothing...

$o->equal($o2)
    compare two digest objects. Returns true only if they're of the same type and they match.

$h{$o->key} = ...
    return the actual digest as a binary string, for use as a key in hashing.

$s = $o->stringize
    convert the digest into a suitable text representation.

$o->write($fh)
    writes an appropriate digest annotation on a packing-list filehandle (see OpenBSD::PackingList(3p) and pkg_create(1)).

SEE ALSO
cksum(1) , Digest::MD5(3p) , Digest::SHA(3p) , Mime::Base64(3p)