{
    "mode": "perldoc",
    "parameter": "Crypt::Digest",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Crypt%3A%3ADigest/json",
    "generated": "2026-06-12T05:15:55Z",
    "synopsis": "### Functional interface:\nuse Crypt::Digest qw( digestdata digestdatahex digestdatab64 digestdatab64u\ndigestfile digestfilehex digestfileb64 digestfileb64u );\n# calculate digest from string/buffer\n$digestraw  = digestdata('SHA1', 'data string');\n$digesthex  = digestdatahex('SHA1', 'data string');\n$digestb64  = digestdatab64('SHA1', 'data string');\n$digestb64u = digestdatab64u('SHA1', 'data string');\n# calculate digest from file\n$digestraw  = digestfile('SHA1', 'filename.dat');\n$digesthex  = digestfilehex('SHA1', 'filename.dat');\n$digestb64  = digestfileb64('SHA1', 'filename.dat');\n$digestb64u = digestfileb64u('SHA1', 'filename.dat');\n# calculate digest from filehandle\n$digestraw  = digestfile('SHA1', *FILEHANDLE);\n$digesthex  = digestfilehex('SHA1', *FILEHANDLE);\n$digestb64  = digestfileb64('SHA1', *FILEHANDLE);\n$digestb64u = digestfileb64u('SHA1', *FILEHANDLE);\n### OO interface:\nuse Crypt::Digest;\n$d = Crypt::Digest->new('SHA1');\n$d->add('any data');\n$d->addfile('filename.dat');\n$d->addfile(*FILEHANDLE);\n$resultraw  = $d->digest;     # raw bytes\n$resulthex  = $d->hexdigest;  # hexadecimal form\n$resultb64  = $d->b64digest;  # Base64 form\n$resultb64u = $d->b64udigest; # Base64 URL Safe form",
    "sections": {
        "NAME": {
            "content": "Crypt::Digest - Generic interface to hash/digest functions\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "### Functional interface:\nuse Crypt::Digest qw( digestdata digestdatahex digestdatab64 digestdatab64u\ndigestfile digestfilehex digestfileb64 digestfileb64u );\n\n# calculate digest from string/buffer\n$digestraw  = digestdata('SHA1', 'data string');\n$digesthex  = digestdatahex('SHA1', 'data string');\n$digestb64  = digestdatab64('SHA1', 'data string');\n$digestb64u = digestdatab64u('SHA1', 'data string');\n# calculate digest from file\n$digestraw  = digestfile('SHA1', 'filename.dat');\n$digesthex  = digestfilehex('SHA1', 'filename.dat');\n$digestb64  = digestfileb64('SHA1', 'filename.dat');\n$digestb64u = digestfileb64u('SHA1', 'filename.dat');\n# calculate digest from filehandle\n$digestraw  = digestfile('SHA1', *FILEHANDLE);\n$digesthex  = digestfilehex('SHA1', *FILEHANDLE);\n$digestb64  = digestfileb64('SHA1', *FILEHANDLE);\n$digestb64u = digestfileb64u('SHA1', *FILEHANDLE);\n\n### OO interface:\nuse Crypt::Digest;\n\n$d = Crypt::Digest->new('SHA1');\n$d->add('any data');\n$d->addfile('filename.dat');\n$d->addfile(*FILEHANDLE);\n$resultraw  = $d->digest;     # raw bytes\n$resulthex  = $d->hexdigest;  # hexadecimal form\n$resultb64  = $d->b64digest;  # Base64 form\n$resultb64u = $d->b64udigest; # Base64 URL Safe form\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Provides an interface to various hash/digest algorithms.\n",
            "subsections": []
        },
        "EXPORT": {
            "content": "Nothing is exported by default.\n\nYou can export selected functions:\n\nuse Crypt::Digest qw( digestdata digestdatahex digestdatab64 digestdatab64u\ndigestfile digestfilehex digestfileb64 digestfileb64u );\n\nOr all of them at once:\n\nuse Crypt::Digest ':all';\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "Please note that all functions take as its first argument the algorithm name, supported values\nare:\n\n'CHAES', 'MD2', 'MD4', 'MD5', 'RIPEMD128', 'RIPEMD160',\n'RIPEMD256', 'RIPEMD320', 'SHA1', 'SHA224', 'SHA256',\n'SHA384', 'SHA512', 'SHA512224', 'SHA512256', 'Tiger192', 'Whirlpool',\n'SHA3224', 'SHA3256', 'SHA3384', 'SHA3512',\n'BLAKE2b160', 'BLAKE2b256', 'BLAKE2b384', 'BLAKE2b512',\n'BLAKE2s128', 'BLAKE2s160', 'BLAKE2s224', 'BLAKE2s256'\n\n(simply any <NAME> for which there is Crypt::Digest::<NAME> module)\n\ndigestdata\nLogically joins all arguments into a single string, and returns its SHA1 digest encoded as a\nbinary string.\n\n$digestraw = digestdata('SHA1', 'data string');\n#or\n$digestraw = digestdata('SHA1', 'any data', 'more data', 'even more data');\n\ndigestdatahex\nLogically joins all arguments into a single string, and returns its SHA1 digest encoded as a\nhexadecimal string.\n\n$digesthex = digestdatahex('SHA1', 'data string');\n#or\n$digesthex = digestdatahex('SHA1', 'any data', 'more data', 'even more data');\n\ndigestdatab64\nLogically joins all arguments into a single string, and returns its SHA1 digest encoded as a\nBase64 string, with trailing '=' padding.\n\n$digestb64 = digestdatab64('SHA1', 'data string');\n#or\n$digestb64 = digestdatab64('SHA1', 'any data', 'more data', 'even more data');\n\ndigestdatab64u\nLogically joins all arguments into a single string, and returns its SHA1 digest encoded as a\nBase64 URL Safe string (see RFC 4648 section 5).\n\n$digestb64url = digestdatab64u('SHA1', 'data string');\n#or\n$digestb64url = digestdatab64u('SHA1', 'any data', 'more data', 'even more data');\n\ndigestfile\nReads file (defined by filename or filehandle) content, and returns its digest encoded as a\nbinary string.\n\n$digestraw = digestfile('SHA1', 'filename.dat');\n#or\n$digestraw = digestfile('SHA1', *FILEHANDLE);\n\ndigestfilehex\nReads file (defined by filename or filehandle) content, and returns its digest encoded as a\nhexadecimal string.\n\n$digesthex = digestfilehex('SHA1', 'filename.dat');\n#or\n$digesthex = digestfilehex('SHA1', *FILEHANDLE);\n\nBEWARE: You have to make sure that the filehandle is in binary mode before you pass it as\nargument to the addfile() method.\n\ndigestfileb64\nReads file (defined by filename or filehandle) content, and returns its digest encoded as a\nBase64 string, with trailing '=' padding.\n\n$digestb64 = digestfileb64('SHA1', 'filename.dat');\n#or\n$digestb64 = digestfileb64('SHA1', *FILEHANDLE);\n\ndigestfileb64u\nReads file (defined by filename or filehandle) content, and returns its digest encoded as a\nBase64 URL Safe string (see RFC 4648 section 5).\n\n$digestb64url = digestfileb64u('SHA1', 'filename.dat');\n#or\n$digestb64url = digestfileb64u('SHA1', *FILEHANDLE);\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new\nConstructor, returns a reference to the digest object.\n\n$d = Crypt::Digest->new($name);\n# $name could be: 'CHAES', 'MD2', 'MD4', 'MD5', 'RIPEMD128', 'RIPEMD160',\n#                 'RIPEMD256', 'RIPEMD320', 'SHA1', 'SHA224', 'SHA256', 'SHA384',\n#                 'SHA512', 'SHA512224', 'SHA512256', 'Tiger192', 'Whirlpool'\n#\n# simply any <FUNCNAME> for which there is Crypt::Digest::<FUNCNAME> module\n\nclone\nCreates a copy of the digest object state and returns a reference to the copy.\n\n$d->clone();\n\nreset\nReinitialize the digest object state and returns a reference to the digest object.\n\n$d->reset();\n\nadd\nAll arguments are appended to the message we calculate digest for. The return value is the\ndigest object itself.\n\n$d->add('any data');\n#or\n$d->add('any data', 'more data', 'even more data');\n\nNote that all the following cases are equivalent:\n\n# case 1\n$d->add('aa', 'bb', 'cc');\n\n# case 2\n$d->add('aa');\n$d->add('bb');\n$d->add('cc');\n\n# case 3\n$d->add('aabbcc');\n\n# case 4\n$d->add('aa')->add('bb')->add('cc');\n\naddfile\nThe content of the file (or filehandle) is appended to the message we calculate digest for. The\nreturn value is the digest object itself.\n\n$d->addfile('filename.dat');\n#or\n$d->addfile(*FILEHANDLE);\n\nBEWARE: You have to make sure that the filehandle is in binary mode before you pass it as\nargument to the addfile() method.\n\naddbits\nThis method is available mostly for compatibility with other Digest::SOMETHING modules on CPAN,\nyou are very unlikely to need it. The return value is the digest object itself.\n\n$d->addbits($bitstring);   # e.g. $d->addbits(\"111100001010\");\n#or\n$d->addbits($data, $nbits); # e.g. $d->addbits(\"\\xF0\\xA0\", 16);\n\nBEWARE: It is not possible to add bits that are not a multiple of 8.\n\nhashsize\nReturns the length of calculated digest in bytes (e.g. 32 for SHA-256).\n\n$d->hashsize;\n#or\nCrypt::Digest->hashsize('SHA1');\n#or\nCrypt::Digest::hashsize('SHA1');\n\ndigest\nReturns the binary digest (raw bytes).\n\n$resultraw = $d->digest();\n\nhexdigest\nReturns the digest encoded as a hexadecimal string.\n\n$resulthex = $d->hexdigest();\n\nb64digest\nReturns the digest encoded as a Base64 string, with trailing '=' padding (BEWARE: this padding\nstyle might differ from other Digest::<SOMETHING> modules on CPAN).\n\n$resultb64 = $d->b64digest();\n\nb64udigest\nReturns the digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).\n\n$resultb64url = $d->b64udigest();\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   CryptX\n\n*   Crypt::Digest tries to be compatible with Digest interface.\n\n*   Check subclasses like Crypt::Digest::SHA1, Crypt::Digest::MD5, ...\n",
            "subsections": []
        }
    },
    "summary": "Crypt::Digest - Generic interface to hash/digest functions",
    "flags": [],
    "examples": [],
    "see_also": []
}