CINXE.COM

Digest - Modules that calculate message digests - metacpan.org

<!DOCTYPE html> <html lang="en-US"> <head> <title>Digest - Modules that calculate message digests - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-XFEQ536G.css" rel="stylesheet" type="text/css"> <script src="/assets/main-WXBSEDQJ.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Digest - MetaCPAN" href="/dist/Digest/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/Digest" /> <meta name="description" content="Modules that calculate message digests" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://perl-ads.perlhacks.com/perl-ads.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/pod/Digest" /> <meta property="og:title" content="Digest" /> <meta property="og:description" content="Modules that calculate message digests" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div id="perl-ad-target" class="top-notify-banner perl-ad-target"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Digest was released."> <span class="relatize">24 Aug 2021 13:51:51 UTC</span> </div> </li> <li> Distribution: <a href="/dist/Digest">Digest</a> </li> <li> Module version: 1.20 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/Digest/source/lib/Digest.pm">Source</a> (<a href="/dist/Digest/source/lib/Digest.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/Digest/source/lib">Browse</a> (<a href="/dist/Digest/source/lib?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/Digest/changes">Changes</a> </li> <li> <a class="nopopup" href="/dist/Digest/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/Dual-Life/digest">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://github.com/Dual-Life/digest/issues">Issues</a> </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Digest+1.20" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Digest.html?oncpan=1&amp;distmat=1&amp;version=1.20&amp;grade=2" style="color: #090">7</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Digest.html?oncpan=1&amp;distmat=1&amp;version=1.20&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Digest.html?oncpan=1&amp;distmat=1&amp;version=1.20&amp;grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/TODDR/Digest-1.20">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Digest who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 5 </div> </li> <li> <a rel="noopener nofollow" href="http://cpancover.com/latest/Digest-1.20/index.html">63.76% Coverage </a> </li> <li> License: perl_5 </li> <li> Perl: v5.6.0 </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/Digest/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/T/TO/TODDR/Digest-1.20.tar.gz"> Download (<span itemprop="fileSize">10.91KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FTODDR%2FDigest-1.20%2Flib%2FDigest.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/Digest/permissions"> Permissions </a> </li> <li> <a href="/dist/Digest/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:Digest"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="Digest"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/TODDR/Digest-1.20/view/lib/Digest.pm" >1.20 (TODDR on 2021-08-24)</option> <option value="/release/TODDR/Digest-1.19/view/lib/Digest.pm" >1.19 (TODDR on 2020-10-13)</option> <option value="/release/GAAS/Digest-1.17/view/lib/Digest.pm" >1.17 (GAAS on 2011-10-02)</option> <optgroup label="BackPAN">' <option value="/release/TODDR/Digest-1.18/view/lib/Digest.pm" >1.18 (TODDR on 2020-10-13)</option> <option value="/release/GAAS/Digest-1.16/view/lib/Digest.pm" >1.16 (GAAS on 2009-06-09)</option> <option value="/release/GAAS/Digest-1.15/view/lib/Digest.pm" >1.15 (GAAS on 2006-03-20)</option> <option value="/release/GAAS/Digest-1.14/view/lib/Digest.pm" >1.14 (GAAS on 2005-11-26)</option> <option value="/release/GAAS/Digest-1.13/view/lib/Digest.pm" >1.13 (GAAS on 2005-10-18)</option> <option value="/release/GAAS/Digest-1.12/view/lib/Digest.pm" >1.12 (GAAS on 2005-09-29)</option> <option value="/release/GAAS/Digest-1.11/view/lib/Digest.pm" >1.11 (GAAS on 2005-09-11)</option> <option value="/release/GAAS/Digest-1.10/view/lib/Digest.pm" >1.10 (GAAS on 2004-11-08)</option> <option value="/release/GAAS/Digest-1.09/view/lib/Digest.pm" >1.09 (GAAS on 2004-11-05)</option> <option value="/release/GAAS/Digest-1.08/view/lib/Digest.pm" >1.08 (GAAS on 2004-04-29)</option> <option value="/release/GAAS/Digest-1.07/view/lib/Digest.pm" >1.07 (GAAS on 2004-04-25)</option> <option value="/release/GAAS/Digest-1.06/view/lib/Digest.pm" >1.06 (GAAS on 2004-04-01)</option> <option value="/release/GAAS/Digest-1.05/view/lib/Digest.pm" >1.05 (GAAS on 2003-12-01)</option> <option value="/release/GAAS/Digest-1.04/view/lib/Digest.pm" >1.04 (GAAS on 2003-11-29)</option> <option value="/release/GAAS/Digest-1.03/view/lib/Digest.pm" >1.03 (GAAS on 2003-11-28)</option> <option value="/release/GAAS/Digest-1.02/view/lib/Digest.pm" >1.02 (GAAS on 2003-01-19)</option> <option value="/release/GAAS/Digest-1.01/view/lib/Digest.pm" >1.01 (GAAS on 2003-01-05)</option> <option value="/release/GAAS/Digest-1.00/view/lib/Digest.pm" >1.00 (GAAS on 2001-03-14)</option> </optgroup> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/TODDR/Digest-1.20/diff/TODDR/Digest-1.20/lib/Digest.pm" >1.20 (TODDR on 2021-08-24)</option> <option value="/release/TODDR/Digest-1.20/diff/TODDR/Digest-1.19/lib/Digest.pm" >1.19 (TODDR on 2020-10-13)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.17/lib/Digest.pm" >1.17 (GAAS on 2011-10-02)</option> <optgroup label="BackPAN">' <option value="/release/TODDR/Digest-1.20/diff/TODDR/Digest-1.18/lib/Digest.pm" >1.18 (TODDR on 2020-10-13)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.16/lib/Digest.pm" >1.16 (GAAS on 2009-06-09)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.15/lib/Digest.pm" >1.15 (GAAS on 2006-03-20)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.14/lib/Digest.pm" >1.14 (GAAS on 2005-11-26)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.13/lib/Digest.pm" >1.13 (GAAS on 2005-10-18)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.12/lib/Digest.pm" >1.12 (GAAS on 2005-09-29)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.11/lib/Digest.pm" >1.11 (GAAS on 2005-09-11)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.10/lib/Digest.pm" >1.10 (GAAS on 2004-11-08)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.09/lib/Digest.pm" >1.09 (GAAS on 2004-11-05)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.08/lib/Digest.pm" >1.08 (GAAS on 2004-04-29)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.07/lib/Digest.pm" >1.07 (GAAS on 2004-04-25)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.06/lib/Digest.pm" >1.06 (GAAS on 2004-04-01)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.05/lib/Digest.pm" >1.05 (GAAS on 2003-12-01)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.04/lib/Digest.pm" >1.04 (GAAS on 2003-11-29)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.03/lib/Digest.pm" >1.03 (GAAS on 2003-11-28)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.02/lib/Digest.pm" >1.02 (GAAS on 2003-01-19)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.01/lib/Digest.pm" >1.01 (GAAS on 2003-01-05)</option> <option value="/release/TODDR/Digest-1.20/diff/GAAS/Digest-1.00/lib/Digest.pm" >1.00 (GAAS on 2001-03-14)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><a href="/pod/MIME::Base64" title="MIME::Base64" class="ellipsis">MIME::Base64</a></li> <li> <hr> </li> <li> <a href="/module/Digest/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=Digest">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=Digest">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/TODDR/Digest-1.20/view/lib/Digest.pm">This version</a> </li> <li> <a href="/pod/Digest">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/RWP"><img src="https://www.gravatar.com/avatar/7110eb2389e69a066d9d7cad7a1cc2bf?d=identicon&amp;s=20" title="RWP" alt="RWP"></a> <a class="display-all" href="/author/KRAUTCAT"><img src="https://www.gravatar.com/avatar/efd137d1577aa9df7fc833f6306958d5?d=identicon&amp;s=20" title="KRAUTCAT" alt="KRAUTCAT"></a> <a class="display-all" href="/author/XAOC"><img src="https://www.gravatar.com/avatar/990db8b0e06746b7d54c36f0603140e1?d=identicon&amp;s=20" title="XAOC" alt="XAOC"></a> <a class="display-all" href="/author/DCPETROV"><img src="https://www.gravatar.com/avatar/10e265a667839a004d83dd3ed6b6cfc9?d=identicon&amp;s=20" title="DCPETROV" alt="DCPETROV"></a> <a class="display-all" href="/author/KEEDI"><img src="https://www.gravatar.com/avatar/95f905a7a4ccc573c711e9d264c0fde8?d=identicon&amp;s=20" title="KEEDI" alt="KEEDI"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/Digest/plussers">5 PAUSE users</a> </div> <div> 6 non-PAUSE users </div> </div> </li> <li> <div> <button class="contributors-show-button btn-link">and 1 contributors</button> <div id="metacpan_contributors" class="slide-out slide-out-hidden"> <div> <ul> <li class="contributor" data-contrib-email="gisle@activestate.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" /> Gisle Aas </li> </ul> </div> </div> </div> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/TODDR" class="author-name">Todd Rinaldo</a> </span> <span>&nbsp;/&nbsp;</span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/TODDR/Digest-1.20/view/lib/Digest.pm" >1.20 (TODDR on 2021-08-24)</option> <option value="/release/TODDR/Digest-1.19/view/lib/Digest.pm" >1.19 (TODDR on 2020-10-13)</option> <option value="/release/GAAS/Digest-1.17/view/lib/Digest.pm" >1.17 (GAAS on 2011-10-02)</option> <optgroup label="BackPAN">' <option value="/release/TODDR/Digest-1.18/view/lib/Digest.pm" >1.18 (TODDR on 2020-10-13)</option> <option value="/release/GAAS/Digest-1.16/view/lib/Digest.pm" >1.16 (GAAS on 2009-06-09)</option> <option value="/release/GAAS/Digest-1.15/view/lib/Digest.pm" >1.15 (GAAS on 2006-03-20)</option> <option value="/release/GAAS/Digest-1.14/view/lib/Digest.pm" >1.14 (GAAS on 2005-11-26)</option> <option value="/release/GAAS/Digest-1.13/view/lib/Digest.pm" >1.13 (GAAS on 2005-10-18)</option> <option value="/release/GAAS/Digest-1.12/view/lib/Digest.pm" >1.12 (GAAS on 2005-09-29)</option> <option value="/release/GAAS/Digest-1.11/view/lib/Digest.pm" >1.11 (GAAS on 2005-09-11)</option> <option value="/release/GAAS/Digest-1.10/view/lib/Digest.pm" >1.10 (GAAS on 2004-11-08)</option> <option value="/release/GAAS/Digest-1.09/view/lib/Digest.pm" >1.09 (GAAS on 2004-11-05)</option> <option value="/release/GAAS/Digest-1.08/view/lib/Digest.pm" >1.08 (GAAS on 2004-04-29)</option> <option value="/release/GAAS/Digest-1.07/view/lib/Digest.pm" >1.07 (GAAS on 2004-04-25)</option> <option value="/release/GAAS/Digest-1.06/view/lib/Digest.pm" >1.06 (GAAS on 2004-04-01)</option> <option value="/release/GAAS/Digest-1.05/view/lib/Digest.pm" >1.05 (GAAS on 2003-12-01)</option> <option value="/release/GAAS/Digest-1.04/view/lib/Digest.pm" >1.04 (GAAS on 2003-11-29)</option> <option value="/release/GAAS/Digest-1.03/view/lib/Digest.pm" >1.03 (GAAS on 2003-11-28)</option> <option value="/release/GAAS/Digest-1.02/view/lib/Digest.pm" >1.02 (GAAS on 2003-01-19)</option> <option value="/release/GAAS/Digest-1.01/view/lib/Digest.pm" >1.01 (GAAS on 2003-01-05)</option> <option value="/release/GAAS/Digest-1.00/view/lib/Digest.pm" >1.00 (GAAS on 2001-03-14)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/Digest">Digest-1.20</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage five &#10; • 77 direct dependents &#10; • 10154 total dependents </title> <rect x="0" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="5" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="10" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="15" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="20" y="0" width="4" height="15" fill="#7ea3f2" /> </g> </svg> </span> <div id="Digest-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="Digest-1.20"> <input type="hidden" name="author" value="TODDR"> <input type="hidden" name="distribution" value="Digest"> <button type="submit" class="favorite highlight"><span>11</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>11</span> ++</button> </div> / <span>Digest</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a></li> <li><a href="#OO-INTERFACE">OO INTERFACE</a></li> <li><a href="#Digest-speed">Digest speed</a></li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>Digest - Modules that calculate message digests</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code>$md5 = Digest-&gt;new(&quot;MD5&quot;); $sha1 = Digest-&gt;new(&quot;SHA-1&quot;); $sha256 = Digest-&gt;new(&quot;SHA-256&quot;); $sha384 = Digest-&gt;new(&quot;SHA-384&quot;); $sha512 = Digest-&gt;new(&quot;SHA-512&quot;); $hmac = Digest-&gt;HMAC_MD5($key);</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>The <code>Digest::</code> modules calculate digests, also called &quot;fingerprints&quot; or &quot;hashes&quot;, 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 or bits.</p> <p>An important property of the digest algorithms is that the digest is <i>likely</i> to change if the message change in some way. Another property is that digest functions are one-way functions, that is it should be <i>hard</i> to find a message that correspond to some given digest. Algorithms differ in how &quot;likely&quot; and how &quot;hard&quot;, as well as how efficient they are to compute.</p> <p>Note that the properties of the algorithms change over time, as the algorithms are analyzed and machines grow faster. If your application for instance depends on it being &quot;impossible&quot; to generate the same digest for a different message it is wise to make it easy to plug in stronger algorithms as the one used grow weaker. Using the interface documented here should make it easy to change algorithms later.</p> <p>All <code>Digest::</code> 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.</p> <p>The digest can be delivered in three formats:</p> <dl> <dt id="binary"><i>binary</i></dt> <dd> <p>This is the most compact form, but it is not well suited for printing or embedding in places that can&#39;t handle arbitrary data.</p> </dd> <dt id="hex"><i>hex</i></dt> <dd> <p>A twice as long string of lowercase hexadecimal digits.</p> </dd> <dt id="base64"><i>base64</i></dt> <dd> <p>A string of portable printable characters. This is the base64 encoded representation of the digest with any trailing padding removed. The string will be about 30% longer than the binary version. <a href="/pod/MIME::Base64">MIME::Base64</a> tells you more about this encoding.</p> </dd> </dl> <p>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:</p> <pre><code>use Digest::MD5 qw(md5); $digest = md5($message);</code></pre> <p>There are also versions of the functions with &quot;_hex&quot; or &quot;_base64&quot; appended to the name, which returns the digest in the indicated form.</p> <h1 id="OO-INTERFACE"><a id="OO"></a>OO INTERFACE</h1> <p>The following methods are available for all <code>Digest::</code> modules:</p> <dl> <dt id="$ctx-=-Digest-&gt;XXX($arg,...)"><a id="ctx-Digest-XXX-arg"></a>$ctx = Digest-&gt;XXX($arg,...)</dt> <dd> </dd> <dt id="$ctx-=-Digest-&gt;new(XXX-=&gt;-$arg,...)"><a id="ctx-Digest-new-XXX-arg"></a>$ctx = Digest-&gt;new(XXX =&gt; $arg,...)</dt> <dd> </dd> <dt id="$ctx-=-Digest::XXX-&gt;new($arg,...)"><a id="ctx-Digest::XXX-new-arg"></a>$ctx = Digest::XXX-&gt;new($arg,...)</dt> <dd> <p>The constructor returns some object that encapsulate the state of the message-digest algorithm. You can add data to the object and finally ask for the digest. The &quot;XXX&quot; should of course be replaced by the proper name of the digest algorithm you want to use.</p> <p>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. &quot;SHA-1&quot;. If no implementation for the given algorithm can be found, then an exception is raised.</p> <p>To know what arguments (if any) the constructor takes (the <code>$args,...</code> above) consult the docs for the specific digest implementation.</p> <p>If new() is called as an instance method (i.e. $ctx-&gt;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).</p> </dd> <dt id="$other_ctx-=-$ctx-&gt;clone"><a id="other_ctx-ctx-clone"></a>$other_ctx = $ctx-&gt;clone</dt> <dd> <p>The clone method creates a copy of the digest state object and returns a reference to the copy.</p> </dd> <dt id="$ctx-&gt;reset"><a id="reset"></a><a id="ctx-reset"></a>$ctx-&gt;reset</dt> <dd> <p>This is just an alias for $ctx-&gt;new.</p> </dd> <dt id="$ctx-&gt;add(-$data-)"><a id="add"></a><a id="ctx-add-data"></a>$ctx-&gt;add( $data )</dt> <dd> </dd> <dt id="$ctx-&gt;add(-$chunk1,-$chunk2,-...-)"><a id="add1"></a><a id="ctx-add-chunk1-chunk2"></a>$ctx-&gt;add( $chunk1, $chunk2, ... )</dt> <dd> <p>The string value of the $data provided as argument is appended to the message we calculate the digest for. The return value is the $ctx object itself.</p> <p>If more arguments are provided then they are all appended to the message, thus all these lines will have the same effect on the state of the $ctx object:</p> <pre><code>$ctx-&gt;add(&quot;a&quot;); $ctx-&gt;add(&quot;b&quot;); $ctx-&gt;add(&quot;c&quot;); $ctx-&gt;add(&quot;a&quot;)-&gt;add(&quot;b&quot;)-&gt;add(&quot;c&quot;); $ctx-&gt;add(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;); $ctx-&gt;add(&quot;abc&quot;);</code></pre> <p>Most algorithms are only defined for strings of bytes and this method might therefore croak if the provided arguments contain chars with ordinal number above 255.</p> </dd> <dt id="$ctx-&gt;addfile(-$io_handle-)"><a id="addfile"></a><a id="ctx-addfile-io_handle"></a>$ctx-&gt;addfile( $io_handle )</dt> <dd> <p>The $io_handle is read until EOF and the content is appended to the message we calculate the digest for. The return value is the $ctx object itself.</p> <p>The addfile() method will croak() if it fails reading data for some reason. If it croaks it is unpredictable what the state of the $ctx 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 $ctx object if this occurs.</p> <p>In most cases you want to make sure that the $io_handle is in &quot;binmode&quot; before you pass it as argument to the addfile() method.</p> </dd> <dt id="$ctx-&gt;add_bits(-$data,-$nbits-)"><a id="add_bits"></a><a id="ctx-add_bits-data-nbits"></a>$ctx-&gt;add_bits( $data, $nbits )</dt> <dd> </dd> <dt id="$ctx-&gt;add_bits(-$bitstring-)"><a id="add_bits1"></a><a id="ctx-add_bits-bitstring"></a>$ctx-&gt;add_bits( $bitstring )</dt> <dd> <p>The add_bits() method is an alternative to add() that allow partial bytes to be appended to the message. Most users can just ignore this method since typical applications involve only whole-byte data.</p> <p>The two argument form of add_bits() will add the first $nbits bits from $data. For the last potentially partial byte only the high order <code>$nbits % 8</code> bits are used. If $nbits is greater than <code>length($data) * 8</code>, then this method would do the same as <code>$ctx-&gt;add($data)</code>.</p> <p>The one argument form of add_bits() takes a $bitstring of &quot;1&quot; and &quot;0&quot; chars as argument. It&#39;s a shorthand for <code>$ctx-&gt;add_bits(pack(&quot;B*&quot;, $bitstring), length($bitstring))</code>.</p> <p>The return value is the $ctx object itself.</p> <p>This example shows two calls that should have the same effect:</p> <pre><code>$ctx-&gt;add_bits(&quot;111100001010&quot;); $ctx-&gt;add_bits(&quot;\xF0\xA0&quot;, 12);</code></pre> <p>Most digest algorithms are byte based and for these it is not possible to add bits that are not a multiple of 8, and the add_bits() method will croak if you try.</p> </dd> <dt id="$ctx-&gt;digest"><a id="digest"></a><a id="ctx-digest"></a>$ctx-&gt;digest</dt> <dd> <p>Return the binary digest for the message.</p> <p>Note that the <code>digest</code> operation is effectively a destructive, read-once operation. Once it has been performed, the $ctx object is automatically <code>reset</code> and can be used to calculate another digest value. Call $ctx-&gt;clone-&gt;digest if you want to calculate the digest without resetting the digest state.</p> </dd> <dt id="$ctx-&gt;hexdigest"><a id="hexdigest"></a><a id="ctx-hexdigest"></a>$ctx-&gt;hexdigest</dt> <dd> <p>Same as $ctx-&gt;digest, but will return the digest in hexadecimal form.</p> </dd> <dt id="$ctx-&gt;b64digest"><a id="b64digest"></a><a id="ctx-b64digest"></a>$ctx-&gt;b64digest</dt> <dd> <p>Same as $ctx-&gt;digest, but will return the digest as a base64 encoded string without padding.</p> </dd> <dt id="$ctx-&gt;base64_padded_digest"><a id="base64_padded_digest"></a><a id="ctx-base64_padded_digest"></a>$ctx-&gt;base64_padded_digest</dt> <dd> <p>Same as $ctx-&gt;digest, but will return the digest as a base64 encoded string.</p> </dd> </dl> <h1 id="Digest-speed"><a id="Digest"></a>Digest speed</h1> <p>This table should give some indication on the relative speed of different algorithms. It is sorted by throughput based on a benchmark done with of some implementations of this API:</p> <pre><code>Algorithm Size Implementation MB/s MD4 128 Digest::MD4 v1.3 165.0 MD5 128 Digest::MD5 v2.33 98.8 SHA-256 256 Digest::SHA2 v1.1.0 66.7 SHA-1 160 Digest::SHA v4.3.1 58.9 SHA-1 160 Digest::SHA1 v2.10 48.8 SHA-256 256 Digest::SHA v4.3.1 41.3 Haval-256 256 Digest::Haval256 v1.0.4 39.8 SHA-384 384 Digest::SHA2 v1.1.0 19.6 SHA-512 512 Digest::SHA2 v1.1.0 19.3 SHA-384 384 Digest::SHA v4.3.1 19.2 SHA-512 512 Digest::SHA v4.3.1 19.2 Whirlpool 512 Digest::Whirlpool v1.0.2 13.0 MD2 128 Digest::MD2 v2.03 9.5 Adler-32 32 Digest::Adler32 v0.03 1.3 CRC-16 16 Digest::CRC v0.05 1.1 CRC-32 32 Digest::CRC v0.05 1.1 MD5 128 Digest::Perl::MD5 v1.5 1.0 CRC-CCITT 16 Digest::CRC v0.05 0.8</code></pre> <p>These numbers was achieved Apr 2004 with ActivePerl-5.8.3 running under Linux on a P4 2.8 GHz CPU. The last 5 entries differ by being pure perl implementations of the algorithms, which explains why they are so slow.</p> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <p><a href="/pod/Digest::Adler32">Digest::Adler32</a>, <a href="/pod/Digest::CRC">Digest::CRC</a>, <a href="/pod/Digest::Haval256">Digest::Haval256</a>, <a href="/pod/Digest::HMAC">Digest::HMAC</a>, <a href="/pod/Digest::MD2">Digest::MD2</a>, <a href="/pod/Digest::MD4">Digest::MD4</a>, <a href="/pod/Digest::MD5">Digest::MD5</a>, <a href="/pod/Digest::SHA">Digest::SHA</a>, <a href="/pod/Digest::SHA1">Digest::SHA1</a>, <a href="/pod/Digest::SHA2">Digest::SHA2</a>, <a href="/pod/Digest::Whirlpool">Digest::Whirlpool</a></p> <p>New digest implementations should consider subclassing from <a href="/pod/Digest::base">Digest::base</a>.</p> <p><a href="/pod/MIME::Base64">MIME::Base64</a></p> <p>http://en.wikipedia.org/wiki/Cryptographic_hash_function</p> <h1 id="AUTHOR">AUTHOR</h1> <p>Gisle Aas &lt;gisle@aas.no&gt;</p> <p>The <code>Digest::</code> interface is based on the interface originally developed by Neil Winton for his <code>MD5</code> module.</p> <p>This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p> <pre><code>Copyright 1998-2006 Gisle Aas. Copyright 1995,1996 Neil Winton.</code></pre></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install Digest, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm Digest</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install Digest</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10