{
    "content": [
        {
            "type": "text",
            "text": "# Digest::MD5 (perldoc)\n\n**Summary:** Digest::MD5 - Perl interface to the MD5 Algorithm\n\n**Synopsis:** # Functional style\nuse Digest::MD5 qw(md5 md5hex md5base64);\n$digest = md5($data);\n$digest = md5hex($data);\n$digest = md5base64($data);\n# OO style\nuse Digest::MD5;\n$ctx = Digest::MD5->new;\n$ctx->add($data);\n$ctx->addfile($filehandle);\n$digest = $ctx->digest;\n$digest = $ctx->hexdigest;\n$digest = $ctx->b64digest;\n\n## Examples\n\n- `The simplest way to use this library is to import the md5hex() function (or one of its`\n- `cousins):`\n- `use Digest::MD5 qw(md5hex);`\n- `print \"Digest is \", md5hex(\"foobarbaz\"), \"\\n\";`\n- `The above example would print out the message:`\n- `Digest is 6df23dc03f9b54cc38a0fc1483df6e21`\n- `The same checksum can also be calculated in OO style:`\n- `use Digest::MD5;`\n- `$md5 = Digest::MD5->new;`\n- `$md5->add('foo', 'bar');`\n- `$md5->add('baz');`\n- `$digest = $md5->hexdigest;`\n- `print \"Digest is $digest\\n\";`\n- `With OO style, you can break the message arbitrarily. This means that we are no longer limited`\n- `to have space for the whole message in memory, i.e. we can handle messages of any size.`\n- `This is useful when calculating checksum for files:`\n- `use Digest::MD5;`\n- `my $filename = shift || \"/etc/passwd\";`\n- `open (my $fh, '<', $filename) or die \"Can't open '$filename': $!\";`\n- `binmode($fh);`\n- `$md5 = Digest::MD5->new;`\n- `while (<$fh>) {`\n- `$md5->add($);`\n- `close($fh);`\n- `print $md5->b64digest, \" $filename\\n\";`\n- `Or we can use the addfile method for more efficient reading of the file:`\n- `use Digest::MD5;`\n- `my $filename = shift || \"/etc/passwd\";`\n- `open (my $fh, '<', $filename) or die \"Can't open '$filename': $!\";`\n- `binmode ($fh);`\n- `print Digest::MD5->new->addfile($fh)->hexdigest, \" $filename\\n\";`\n- `Since the MD5 algorithm is only defined for strings of bytes, it can not be used on strings that`\n- `contains chars with ordinal number above 255 (Unicode strings). The MD5 functions and methods`\n- `will croak if you try to feed them such input data:`\n- `use Digest::MD5 qw(md5hex);`\n- `my $str = \"abc\\x{300}\";`\n- `print md5hex($str), \"\\n\";  # croaks`\n- `# Wide character in subroutine entry`\n- `What you can do is calculate the MD5 checksum of the UTF-8 representation of such strings. This`\n- `is achieved by filtering the string through encodeutf8() function:`\n- `use Digest::MD5 qw(md5hex);`\n- `use Encode qw(encodeutf8);`\n- `my $str = \"abc\\x{300}\";`\n- `print md5hex(encodeutf8($str)), \"\\n\";`\n- `# 8c2d46911f3f5a326455f0ed7a8ed3b3`\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (19 lines)\n- **DESCRIPTION** (13 lines)\n- **FUNCTIONS** (3 lines) — 3 subsections\n  - md5 (5 lines)\n  - md5_hex (3 lines)\n  - md5_base64 (8 lines)\n- **METHODS** (86 lines)\n- **EXAMPLES** (69 lines)\n- **SEE ALSO** (2 lines) — 1 subsections\n  - md5sum (6 lines)\n- **COPYRIGHT** (30 lines)\n- **AUTHORS** (4 lines)\n\n## Full Content\n\n### NAME\n\nDigest::MD5 - Perl interface to the MD5 Algorithm\n\n### SYNOPSIS\n\n# Functional style\nuse Digest::MD5 qw(md5 md5hex md5base64);\n\n$digest = md5($data);\n$digest = md5hex($data);\n$digest = md5base64($data);\n\n# OO style\nuse Digest::MD5;\n\n$ctx = Digest::MD5->new;\n\n$ctx->add($data);\n$ctx->addfile($filehandle);\n\n$digest = $ctx->digest;\n$digest = $ctx->hexdigest;\n$digest = $ctx->b64digest;\n\n### DESCRIPTION\n\nThe \"Digest::MD5\" module allows you to use the RSA Data Security Inc. MD5 Message Digest\nalgorithm from within Perl programs. The algorithm takes as input a message of arbitrary length\nand produces as output a 128-bit \"fingerprint\" or \"message digest\" of the input.\n\nNote that the MD5 algorithm is not as strong as it used to be. It has since 2005 been easy to\ngenerate different messages that produce the same MD5 digest. It still seems hard to generate\nmessages that produce a given digest, but it is probably wise to move to stronger algorithms for\napplications that depend on the digest to uniquely identify a message.\n\nThe \"Digest::MD5\" module provide a procedural interface for simple use, as well as an object\noriented interface that can handle messages of arbitrary length and which can read files\ndirectly.\n\n### FUNCTIONS\n\nThe following functions are provided by the \"Digest::MD5\" module. None of these functions are\nexported by default.\n\n#### md5\n\nThis function will concatenate all arguments, calculate the MD5 digest of this \"message\",\nand return it in binary form. The returned string will be 16 bytes long.\n\nThe result of md5(\"a\", \"b\", \"c\") will be exactly the same as the result of md5(\"abc\").\n\n#### md5_hex\n\nSame as md5(), but will return the digest in hexadecimal form. The length of the returned\nstring will be 32 and it will only contain characters from this set: '0'..'9' and 'a'..'f'.\n\n#### md5_base64\n\nSame as md5(), but will return the digest as a base64 encoded string. The length of the\nreturned string will be 22 and it will only contain characters from this set: 'A'..'Z',\n'a'..'z', '0'..'9', '+' and '/'.\n\nNote that the base64 encoded string returned is not padded to be a multiple of 4 bytes long.\nIf you want interoperability with other base64 encoded md5 digests you might want to append\nthe redundant string \"==\" to the result.\n\n### METHODS\n\nThe object oriented interface to \"Digest::MD5\" is described in this section. After a\n\"Digest::MD5\" object has been created, you will add data to it and finally ask for the digest in\na suitable format. A single object can be used to calculate multiple digests.\n\nThe following methods are provided:\n\n$md5 = Digest::MD5->new\nThe constructor returns a new \"Digest::MD5\" object which encapsulate the state of the MD5\nmessage-digest algorithm.\n\nIf called as an instance method (i.e. $md5->new) it will just reset the state the object to\nthe state of a newly created object. No new object is created in this case.\n\n$md5->reset\nThis is just an alias for $md5->new.\n\n$md5->clone\nThis a copy of the $md5 object. It is useful when you do not want to destroy the digests\nstate, but need an intermediate value of the digest, e.g. when calculating digests\niteratively on a continuous data stream. Example:\n\nmy $md5 = Digest::MD5->new;\nwhile (<>) {\n$md5->add($);\nprint \"Line $.: \", $md5->clone->hexdigest, \"\\n\";\n}\n\n$md5->add($data,...)\nThe $data provided as argument are appended to the message we calculate the digest for. The\nreturn value is the $md5 object itself.\n\nAll these lines will have the same effect on the state of the $md5 object:\n\n$md5->add(\"a\"); $md5->add(\"b\"); $md5->add(\"c\");\n$md5->add(\"a\")->add(\"b\")->add(\"c\");\n$md5->add(\"a\", \"b\", \"c\");\n$md5->add(\"abc\");\n\n$md5->addfile($iohandle)\nThe $iohandle will be read until EOF and its content appended to the message we calculate\nthe digest for. The return value is the $md5 object itself.\n\nThe addfile() method will croak() if it fails reading data for some reason. If it croaks it\nis unpredictable what the state of the $md5 object will be in. The addfile() method might\nhave been able to read the file partially before it failed. It is probably wise to discard\nor reset the $md5 object if this occurs.\n\nIn most cases you want to make sure that the $iohandle is in \"binmode\" before you pass it\nas argument to the addfile() method.\n\n$md5->addbits($data, $nbits)\n$md5->addbits($bitstring)\nSince the MD5 algorithm is byte oriented you might only add bits as multiples of 8, so you\nprobably want to just use add() instead. The addbits() method is provided for compatibility\nwith other digest implementations. See Digest for description of the arguments that\naddbits() take.\n\n$md5->digest\nReturn the binary digest for the message. The returned string will be 16 bytes long.\n\nNote that the \"digest\" operation is effectively a destructive, read-once operation. Once it\nhas been performed, the \"Digest::MD5\" object is automatically \"reset\" and can be used to\ncalculate another digest value. Call $md5->clone->digest if you want to calculate the digest\nwithout resetting the digest state.\n\n$md5->hexdigest\nSame as $md5->digest, but will return the digest in hexadecimal form. The length of the\nreturned string will be 32 and it will only contain characters from this set: '0'..'9' and\n'a'..'f'.\n\n$md5->b64digest\nSame as $md5->digest, but will return the digest as a base64 encoded string. The length of\nthe returned string will be 22 and it will only contain characters from this set: 'A'..'Z',\n'a'..'z', '0'..'9', '+' and '/'.\n\nThe base64 encoded string returned is not padded to be a multiple of 4 bytes long. If you\nwant interoperability with other base64 encoded md5 digests you might want to append the\nstring \"==\" to the result.\n\n@ctx = $md5->context\n$md5->context(@ctx)\nSaves or restores the internal state. When called with no arguments, returns a list: number\nof blocks processed, a 16-byte internal state buffer, then optionally up to 63 bytes of\nunprocessed data if there are any. When passed those same arguments, restores the state.\nThis is only useful for specialised operations.\n\n### EXAMPLES\n\nThe simplest way to use this library is to import the md5hex() function (or one of its\ncousins):\n\nuse Digest::MD5 qw(md5hex);\nprint \"Digest is \", md5hex(\"foobarbaz\"), \"\\n\";\n\nThe above example would print out the message:\n\nDigest is 6df23dc03f9b54cc38a0fc1483df6e21\n\nThe same checksum can also be calculated in OO style:\n\nuse Digest::MD5;\n\n$md5 = Digest::MD5->new;\n$md5->add('foo', 'bar');\n$md5->add('baz');\n$digest = $md5->hexdigest;\n\nprint \"Digest is $digest\\n\";\n\nWith OO style, you can break the message arbitrarily. This means that we are no longer limited\nto have space for the whole message in memory, i.e. we can handle messages of any size.\n\nThis is useful when calculating checksum for files:\n\nuse Digest::MD5;\n\nmy $filename = shift || \"/etc/passwd\";\nopen (my $fh, '<', $filename) or die \"Can't open '$filename': $!\";\nbinmode($fh);\n\n$md5 = Digest::MD5->new;\nwhile (<$fh>) {\n$md5->add($);\n}\nclose($fh);\nprint $md5->b64digest, \" $filename\\n\";\n\nOr we can use the addfile method for more efficient reading of the file:\n\nuse Digest::MD5;\n\nmy $filename = shift || \"/etc/passwd\";\nopen (my $fh, '<', $filename) or die \"Can't open '$filename': $!\";\nbinmode ($fh);\n\nprint Digest::MD5->new->addfile($fh)->hexdigest, \" $filename\\n\";\n\nSince the MD5 algorithm is only defined for strings of bytes, it can not be used on strings that\ncontains chars with ordinal number above 255 (Unicode strings). The MD5 functions and methods\nwill croak if you try to feed them such input data:\n\nuse Digest::MD5 qw(md5hex);\n\nmy $str = \"abc\\x{300}\";\nprint md5hex($str), \"\\n\";  # croaks\n# Wide character in subroutine entry\n\nWhat you can do is calculate the MD5 checksum of the UTF-8 representation of such strings. This\nis achieved by filtering the string through encodeutf8() function:\n\nuse Digest::MD5 qw(md5hex);\nuse Encode qw(encodeutf8);\n\nmy $str = \"abc\\x{300}\";\nprint md5hex(encodeutf8($str)), \"\\n\";\n# 8c2d46911f3f5a326455f0ed7a8ed3b3\n\n### SEE ALSO\n\nDigest, Digest::MD2, Digest::SHA, Digest::HMAC\n\n#### md5sum\n\nRFC 1321\n\nhttp://en.wikipedia.org/wiki/MD5\n\nThe paper \"How to Break MD5 and Other Hash Functions\" by Xiaoyun Wang and Hongbo Yu.\n\n### COPYRIGHT\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nCopyright 1998-2003 Gisle Aas.\nCopyright 1995-1996 Neil Winton.\nCopyright 1991-1992 RSA Data Security, Inc.\n\nThe MD5 algorithm is defined in RFC 1321. This implementation is derived from the reference C\ncode in RFC 1321 which is covered by the following copyright statement:\n\n*   Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.\n\nLicense to copy and use this software is granted provided that it is identified as the \"RSA\nData Security, Inc. MD5 Message-Digest Algorithm\" in all material mentioning or referencing\nthis software or this function.\n\nLicense is also granted to make and use derivative works provided that such works are\nidentified as \"derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm\" in all\nmaterial mentioning or referencing the derived work.\n\nRSA Data Security, Inc. makes no representations concerning either the merchantability of\nthis software or the suitability of this software for any particular purpose. It is provided\n\"as is\" without express or implied warranty of any kind.\n\nThese notices must be retained in any copies of any part of this documentation and/or\nsoftware.\n\nThis copyright does not prohibit distribution of any version of Perl containing this extension\nunder the terms of the GNU or Artistic licenses.\n\n### AUTHORS\n\nThe original \"MD5\" interface was written by Neil Winton (\"N.Winton@axion.bt.co.uk\").\n\nThe \"Digest::MD5\" module is written by Gisle Aas <gisle@ActiveState.com>.\n\n"
        }
    ],
    "structuredContent": {
        "command": "Digest::MD5",
        "section": "",
        "mode": "perldoc",
        "summary": "Digest::MD5 - Perl interface to the MD5 Algorithm",
        "synopsis": "# Functional style\nuse Digest::MD5 qw(md5 md5hex md5base64);\n$digest = md5($data);\n$digest = md5hex($data);\n$digest = md5base64($data);\n# OO style\nuse Digest::MD5;\n$ctx = Digest::MD5->new;\n$ctx->add($data);\n$ctx->addfile($filehandle);\n$digest = $ctx->digest;\n$digest = $ctx->hexdigest;\n$digest = $ctx->b64digest;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "The simplest way to use this library is to import the md5hex() function (or one of its",
            "cousins):",
            "use Digest::MD5 qw(md5hex);",
            "print \"Digest is \", md5hex(\"foobarbaz\"), \"\\n\";",
            "The above example would print out the message:",
            "Digest is 6df23dc03f9b54cc38a0fc1483df6e21",
            "The same checksum can also be calculated in OO style:",
            "use Digest::MD5;",
            "$md5 = Digest::MD5->new;",
            "$md5->add('foo', 'bar');",
            "$md5->add('baz');",
            "$digest = $md5->hexdigest;",
            "print \"Digest is $digest\\n\";",
            "With OO style, you can break the message arbitrarily. This means that we are no longer limited",
            "to have space for the whole message in memory, i.e. we can handle messages of any size.",
            "This is useful when calculating checksum for files:",
            "use Digest::MD5;",
            "my $filename = shift || \"/etc/passwd\";",
            "open (my $fh, '<', $filename) or die \"Can't open '$filename': $!\";",
            "binmode($fh);",
            "$md5 = Digest::MD5->new;",
            "while (<$fh>) {",
            "$md5->add($);",
            "close($fh);",
            "print $md5->b64digest, \" $filename\\n\";",
            "Or we can use the addfile method for more efficient reading of the file:",
            "use Digest::MD5;",
            "my $filename = shift || \"/etc/passwd\";",
            "open (my $fh, '<', $filename) or die \"Can't open '$filename': $!\";",
            "binmode ($fh);",
            "print Digest::MD5->new->addfile($fh)->hexdigest, \" $filename\\n\";",
            "Since the MD5 algorithm is only defined for strings of bytes, it can not be used on strings that",
            "contains chars with ordinal number above 255 (Unicode strings). The MD5 functions and methods",
            "will croak if you try to feed them such input data:",
            "use Digest::MD5 qw(md5hex);",
            "my $str = \"abc\\x{300}\";",
            "print md5hex($str), \"\\n\";  # croaks",
            "# Wide character in subroutine entry",
            "What you can do is calculate the MD5 checksum of the UTF-8 representation of such strings. This",
            "is achieved by filtering the string through encodeutf8() function:",
            "use Digest::MD5 qw(md5hex);",
            "use Encode qw(encodeutf8);",
            "my $str = \"abc\\x{300}\";",
            "print md5hex(encodeutf8($str)), \"\\n\";",
            "# 8c2d46911f3f5a326455f0ed7a8ed3b3"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "FUNCTIONS",
                "lines": 3,
                "subsections": [
                    {
                        "name": "md5",
                        "lines": 5
                    },
                    {
                        "name": "md5_hex",
                        "lines": 3
                    },
                    {
                        "name": "md5_base64",
                        "lines": 8
                    }
                ]
            },
            {
                "name": "METHODS",
                "lines": 86,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 69,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": [
                    {
                        "name": "md5sum",
                        "lines": 6
                    }
                ]
            },
            {
                "name": "COPYRIGHT",
                "lines": 30,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 4,
                "subsections": []
            }
        ]
    }
}