{
    "content": [
        {
            "type": "text",
            "text": "# Digest (man)\n\n## NAME\n\nDigest - Modules that calculate message digests\n\n## SYNOPSIS\n\n$md5  = Digest->new(\"MD5\");\n$sha1 = Digest->new(\"SHA-1\");\n$sha256 = Digest->new(\"SHA-256\");\n$sha384 = Digest->new(\"SHA-384\");\n$sha512 = Digest->new(\"SHA-512\");\n$hmac = Digest->HMACMD5($key);\n\n## DESCRIPTION\n\nThe \"Digest::\" modules calculate digests, also called \"fingerprints\" or \"hashes\", of some\ndata, called a message.  The digest is (usually) some small/fixed size string.  The actual\nsize of the digest depend of the algorithm used.  The message is simply a sequence of\narbitrary bytes or bits.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OO INTERFACE** (1 subsections)\n- **SEE ALSO**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Digest",
        "section": "",
        "mode": "man",
        "summary": "Digest - Modules that calculate message digests",
        "synopsis": "$md5  = Digest->new(\"MD5\");\n$sha1 = Digest->new(\"SHA-1\");\n$sha256 = Digest->new(\"SHA-256\");\n$sha384 = Digest->new(\"SHA-384\");\n$sha512 = Digest->new(\"SHA-512\");\n$hmac = Digest->HMACMD5($key);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 40,
                "subsections": []
            },
            {
                "name": "OO INTERFACE",
                "lines": 98,
                "subsections": [
                    {
                        "name": "Digest speed",
                        "lines": 29
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 14,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Digest - Modules that calculate message digests\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "$md5  = Digest->new(\"MD5\");\n$sha1 = Digest->new(\"SHA-1\");\n$sha256 = Digest->new(\"SHA-256\");\n$sha384 = Digest->new(\"SHA-384\");\n$sha512 = Digest->new(\"SHA-512\");\n\n$hmac = Digest->HMACMD5($key);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The \"Digest::\" modules calculate digests, also called \"fingerprints\" or \"hashes\", of some\ndata, called a message.  The digest is (usually) some small/fixed size string.  The actual\nsize of the digest depend of the algorithm used.  The message is simply a sequence of\narbitrary bytes or bits.\n\nAn important property of the digest algorithms is that the digest is likely to change if the\nmessage change in some way.  Another property is that digest functions are one-way functions,\nthat is it should be hard to find a message that correspond to some given digest.  Algorithms\ndiffer in how \"likely\" and how \"hard\", as well as how efficient they are to compute.\n\nNote that the properties of the algorithms change over time, as the algorithms are analyzed\nand machines grow faster.  If your application for instance depends on it being \"impossible\"\nto generate the same digest for a different message it is wise to make it easy to plug in\nstronger algorithms as the one used grow weaker.  Using the interface documented here should\nmake it easy to change algorithms later.\n\nAll \"Digest::\" modules provide the same programming interface.  A functional interface for\nsimple use, as well as an object oriented interface that can handle messages of arbitrary\nlength and which can read files directly.\n\nThe digest can be delivered in three formats:\n\nbinary  This is the most compact form, but it is not well suited for printing or embedding in\nplaces that can't handle arbitrary data.\n\nhex     A twice as long string of lowercase hexadecimal digits.\n\nbase64  A string of portable printable characters.  This is the base64 encoded representation\nof the digest with any trailing padding removed.  The string will be about 30% longer\nthan the binary version.  MIME::Base64 tells you more about this encoding.\n\nThe functional interface is simply importable functions with the same name as the algorithm.\nThe functions take the message as argument and return the digest.  Example:\n\nuse Digest::MD5 qw(md5);\n$digest = md5($message);\n\nThere are also versions of the functions with \"hex\" or \"base64\" appended to the name, which\nreturns the digest in the indicated form.\n",
                "subsections": []
            },
            "OO INTERFACE": {
                "content": "The following methods are available for all \"Digest::\" modules:\n\n$ctx = Digest->XXX($arg,...)\n$ctx = Digest->new(XXX => $arg,...)\n$ctx = Digest::XXX->new($arg,...)\nThe constructor returns some object that encapsulate the state of the message-digest\nalgorithm.  You can add data to the object and finally ask for the digest.  The \"XXX\"\nshould of course be replaced by the proper name of the digest algorithm you want to use.\n\nThe two first forms are simply syntactic sugar which automatically load the right module\non first use.  The second form allow you to use algorithm names which contains letters\nwhich are not legal perl identifiers, e.g. \"SHA-1\".  If no implementation for the given\nalgorithm can be found, then an exception is raised.\n\nTo know what arguments (if any) the constructor takes (the \"$args,...\" above) consult the\ndocs for the specific digest implementation.\n\nIf new() is called as an instance method (i.e. $ctx->new) it will just reset the state\nthe object to the state of a newly created object.  No new object is created in this\ncase, and the return value is the reference to the object (i.e. $ctx).\n\n$otherctx = $ctx->clone\nThe clone method creates a copy of the digest state object and returns a reference to the\ncopy.\n\n$ctx->reset\nThis is just an alias for $ctx->new.\n\n$ctx->add( $data )\n$ctx->add( $chunk1, $chunk2, ... )\nThe string value of the $data provided as argument is appended to the message we\ncalculate the digest for.  The return value is the $ctx object itself.\n\nIf more arguments are provided then they are all appended to the message, thus all these\nlines will have the same effect on the state of the $ctx object:\n\n$ctx->add(\"a\"); $ctx->add(\"b\"); $ctx->add(\"c\");\n$ctx->add(\"a\")->add(\"b\")->add(\"c\");\n$ctx->add(\"a\", \"b\", \"c\");\n$ctx->add(\"abc\");\n\nMost algorithms are only defined for strings of bytes and this method might therefore\ncroak if the provided arguments contain chars with ordinal number above 255.\n\n$ctx->addfile( $iohandle )\nThe $iohandle is read until EOF and the content is appended to the message we calculate\nthe digest for.  The return value is the $ctx object itself.\n\nThe addfile() method will croak() if it fails reading data for some reason.  If it croaks\nit is unpredictable what the state of the $ctx object will be in. The addfile() method\nmight have been able to read the file partially before it failed.  It is probably wise to\ndiscard or reset the $ctx object if this occurs.\n\nIn most cases you want to make sure that the $iohandle is in \"binmode\" before you pass\nit as argument to the addfile() method.\n\n$ctx->addbits( $data, $nbits )\n$ctx->addbits( $bitstring )\nThe addbits() method is an alternative to add() that allow partial bytes to be appended\nto the message.  Most users can just ignore this method since typical applications\ninvolve only whole-byte data.\n\nThe two argument form of addbits() will add the first $nbits bits from $data.  For the\nlast potentially partial byte only the high order \"$nbits % 8\" bits are used.  If $nbits\nis greater than \"length($data) * 8\", then this method would do the same as\n\"$ctx->add($data)\".\n\nThe one argument form of addbits() takes a $bitstring of \"1\" and \"0\" chars as argument.\nIt's a shorthand for \"$ctx->addbits(pack(\"B*\", $bitstring), length($bitstring))\".\n\nThe return value is the $ctx object itself.\n\nThis example shows two calls that should have the same effect:\n\n$ctx->addbits(\"111100001010\");\n$ctx->addbits(\"\\xF0\\xA0\", 12);\n\nMost digest algorithms are byte based and for these it is not possible to add bits that\nare not a multiple of 8, and the addbits() method will croak if you try.\n\n$ctx->digest\nReturn the binary digest for the message.\n\nNote that the \"digest\" operation is effectively a destructive, read-once operation. Once\nit has been performed, the $ctx object is automatically \"reset\" and can be used to\ncalculate another digest value.  Call $ctx->clone->digest if you want to calculate the\ndigest without resetting the digest state.\n\n$ctx->hexdigest\nSame as $ctx->digest, but will return the digest in hexadecimal form.\n\n$ctx->b64digest\nSame as $ctx->digest, but will return the digest as a base64 encoded string without\npadding.\n\n$ctx->base64paddeddigest\nSame as $ctx->digest, but will return the digest as a base64 encoded string.\n",
                "subsections": [
                    {
                        "name": "Digest speed",
                        "content": "This table should give some indication on the relative speed of different algorithms.  It is\nsorted by throughput based on a benchmark done with of some implementations of this API:\n\nAlgorithm      Size    Implementation                  MB/s\n\nMD4            128     Digest::MD4 v1.3               165.0\nMD5            128     Digest::MD5 v2.33               98.8\nSHA-256        256     Digest::SHA2 v1.1.0             66.7\nSHA-1          160     Digest::SHA v4.3.1              58.9\nSHA-1          160     Digest::SHA1 v2.10              48.8\nSHA-256        256     Digest::SHA v4.3.1              41.3\nHaval-256      256     Digest::Haval256 v1.0.4         39.8\nSHA-384        384     Digest::SHA2 v1.1.0             19.6\nSHA-512        512     Digest::SHA2 v1.1.0             19.3\nSHA-384        384     Digest::SHA v4.3.1              19.2\nSHA-512        512     Digest::SHA v4.3.1              19.2\nWhirlpool      512     Digest::Whirlpool v1.0.2        13.0\nMD2            128     Digest::MD2 v2.03                9.5\n\nAdler-32        32     Digest::Adler32 v0.03            1.3\nCRC-16          16     Digest::CRC v0.05                1.1\nCRC-32          32     Digest::CRC v0.05                1.1\nMD5            128     Digest::Perl::MD5 v1.5           1.0\nCRC-CCITT       16     Digest::CRC v0.05                0.8\n\nThese numbers was achieved Apr 2004 with ActivePerl-5.8.3 running under Linux on a P4 2.8 GHz\nCPU.  The last 5 entries differ by being pure perl implementations of the algorithms, which\nexplains why they are so slow.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "Digest::Adler32, Digest::CRC, Digest::Haval256, Digest::HMAC, Digest::MD2, Digest::MD4,\nDigest::MD5, Digest::SHA, Digest::SHA1, Digest::SHA2, Digest::Whirlpool\n\nNew digest implementations should consider subclassing from Digest::base.\n\nMIME::Base64\n\nhttp://en.wikipedia.org/wiki/Cryptographichashfunction\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Gisle Aas <gisle@aas.no>\n\nThe \"Digest::\" interface is based on the interface originally developed by Neil Winton for\nhis \"MD5\" module.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms\nas Perl itself.\n\nCopyright 1998-2006 Gisle Aas.\nCopyright 1995,1996 Neil Winton.\n\n\n\nperl v5.34.0                                 2025-07-25                                Digest(3perl)",
                "subsections": []
            }
        }
    }
}