⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digest::md5.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
destroy the digests state, but need an intermediate value of thedigest, e.g. when calculating digests iteratively on a continuous datastream.  Example:.Sp.Vb 5\&    my $md5 = Digest::MD5\->new;\&    while (<>) {\&        $md5\->add($_);\&        print "Line $.: ", $md5\->clone\->hexdigest, "\en";\&    }.Ve.ie n .IP "$md5\->add($data,...)" 4.el .IP "\f(CW$md5\fR\->add($data,...)" 4.IX Item "$md5->add($data,...)"The \f(CW$data\fR provided as argument are appended to the message wecalculate the digest for.  The return value is the \f(CW$md5\fR object itself..SpAll these lines will have the same effect on the state of the \f(CW$md5\fRobject:.Sp.Vb 4\&    $md5\->add("a"); $md5\->add("b"); $md5\->add("c");\&    $md5\->add("a")\->add("b")\->add("c");\&    $md5\->add("a", "b", "c");\&    $md5\->add("abc");.Ve.ie n .IP "$md5\->addfile($io_handle)" 4.el .IP "\f(CW$md5\fR\->addfile($io_handle)" 4.IX Item "$md5->addfile($io_handle)"The \f(CW$io_handle\fR will be read until \s-1EOF\s0 and its content appended to themessage we calculate the digest for.  The return value is the \f(CW$md5\fRobject itself..SpThe \fIaddfile()\fR method will \fIcroak()\fR if it fails reading data for somereason.  If it croaks it is unpredictable what the state of the \f(CW$md5\fRobject will be in. The \fIaddfile()\fR method might have been able to readthe file partially before it failed.  It is probably wise to discardor reset the \f(CW$md5\fR object if this occurs..SpIn most cases you want to make sure that the \f(CW$io_handle\fR is in\&\f(CW\*(C`binmode\*(C'\fR before you pass it as argument to the \fIaddfile()\fR method..ie n .IP "$md5\fR\->add_bits($data, \f(CW$nbits)" 4.el .IP "\f(CW$md5\fR\->add_bits($data, \f(CW$nbits\fR)" 4.IX Item "$md5->add_bits($data, $nbits)".PD 0.ie n .IP "$md5\->add_bits($bitstring)" 4.el .IP "\f(CW$md5\fR\->add_bits($bitstring)" 4.IX Item "$md5->add_bits($bitstring)".PDSince the \s-1MD5\s0 algorithm is byte oriented you might only add bits asmultiples of 8, so you probably want to just use \fIadd()\fR instead.  The\&\fIadd_bits()\fR method is provided for compatibility with other digestimplementations.  See Digest for description of the argumentsthat \fIadd_bits()\fR take..ie n .IP "$md5\->digest" 4.el .IP "\f(CW$md5\fR\->digest" 4.IX Item "$md5->digest"Return the binary digest for the message.  The returned string will be16 bytes long..SpNote that the \f(CW\*(C`digest\*(C'\fR operation is effectively a destructive,read-once operation. Once it has been performed, the \f(CW\*(C`Digest::MD5\*(C'\fRobject is automatically \f(CW\*(C`reset\*(C'\fR and can be used to calculate anotherdigest value.  Call \f(CW$md5\fR\->clone\->digest if you want to calculate thedigest without resetting the digest state..ie n .IP "$md5\->hexdigest" 4.el .IP "\f(CW$md5\fR\->hexdigest" 4.IX Item "$md5->hexdigest"Same as \f(CW$md5\fR\->digest, but will return the digest in hexadecimalform. The length of the returned string will be 32 and it will onlycontain characters from this set: '0'..'9' and 'a'..'f'..ie n .IP "$md5\->b64digest" 4.el .IP "\f(CW$md5\fR\->b64digest" 4.IX Item "$md5->b64digest"Same as \f(CW$md5\fR\->digest, but will return the digest as a base64 encodedstring.  The length of the returned string will be 22 and it will onlycontain characters from this set: 'A'..'Z', 'a'..'z', '0'..'9', '+'and '/'..SpThe base64 encoded string returned is not padded to be a multiple of 4bytes long.  If you want interoperability with other base64 encodedmd5 digests you might want to append the string \*(L"==\*(R" to the result..SH "EXAMPLES".IX Header "EXAMPLES"The simplest way to use this library is to import the \fImd5_hex()\fRfunction (or one of its cousins):.PP.Vb 2\&    use Digest::MD5 qw(md5_hex);\&    print "Digest is ", md5_hex("foobarbaz"), "\en";.Ve.PPThe above example would print out the message:.PP.Vb 1\&    Digest is 6df23dc03f9b54cc38a0fc1483df6e21.Ve.PPThe same checksum can also be calculated in \s-1OO\s0 style:.PP.Vb 1\&    use Digest::MD5;\&    \&    $md5 = Digest::MD5\->new;\&    $md5\->add(\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq);\&    $md5\->add(\*(Aqbaz\*(Aq);\&    $digest = $md5\->hexdigest;\&    \&    print "Digest is $digest\en";.Ve.PPWith \s-1OO\s0 style you can break the message arbitrary.  This means that weare no longer limited to have space for the whole message in memory, i.e.we can handle messages of any size..PPThis is useful when calculating checksum for files:.PP.Vb 1\&    use Digest::MD5;\&\&    my $file = shift || "/etc/passwd";\&    open(FILE, $file) or die "Can\*(Aqt open \*(Aq$file\*(Aq: $!";\&    binmode(FILE);\&\&    $md5 = Digest::MD5\->new;\&    while (<FILE>) {\&        $md5\->add($_);\&    }\&    close(FILE);\&    print $md5\->b64digest, " $file\en";.Ve.PPOr we can use the addfile method for more efficient reading ofthe file:.PP.Vb 1\&    use Digest::MD5;\&\&    my $file = shift || "/etc/passwd";\&    open(FILE, $file) or die "Can\*(Aqt open \*(Aq$file\*(Aq: $!";\&    binmode(FILE);\&\&    print Digest::MD5\->new\->addfile(*FILE)\->hexdigest, " $file\en";.Ve.PPPerl 5.8 support Unicode characters in strings.  Since the \s-1MD5\s0algorithm is only defined for strings of bytes, it can not be used onstrings that contains chars with ordinal number above 255.  The \s-1MD5\s0functions and methods will croak if you try to feed them such inputdata:.PP.Vb 1\&    use Digest::MD5 qw(md5_hex);\&\&    my $str = "abc\ex{300}";\&    print md5_hex($str), "\en";  # croaks\&    # Wide character in subroutine entry.Ve.PPWhat you can do is calculate the \s-1MD5\s0 checksum of the \s-1UTF\-8\s0representation of such strings.  This is achieved by filtering thestring through \fIencode_utf8()\fR function:.PP.Vb 2\&    use Digest::MD5 qw(md5_hex);\&    use Encode qw(encode_utf8);\&\&    my $str = "abc\ex{300}";\&    print md5_hex(encode_utf8($str)), "\en";\&    # 8c2d46911f3f5a326455f0ed7a8ed3b3.Ve.SH "SEE ALSO".IX Header "SEE ALSO"Digest,Digest::MD2,Digest::SHA1,Digest::HMAC.PP\&\fImd5sum\fR\|(1).PP\&\s-1RFC\s0 1321.PPhttp://en.wikipedia.org/wiki/MD5.PPThe paper \*(L"How to Break \s-1MD5\s0 and Other Hash Functions\*(R" by Xiaoyun Wangand Hongbo Yu..SH "COPYRIGHT".IX Header "COPYRIGHT"This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself..PP.Vb 3\& Copyright 1998\-2003 Gisle Aas.\& Copyright 1995\-1996 Neil Winton.\& Copyright 1991\-1992 RSA Data Security, Inc..Ve.PPThe \s-1MD5\s0 algorithm is defined in \s-1RFC\s0 1321. This implementation isderived from the reference C code in \s-1RFC\s0 1321 which is covered bythe following copyright statement:.IP "\(bu" 4Copyright (C) 1991\-2, \s-1RSA\s0 Data Security, Inc. Created 1991. Allrights reserved..SpLicense to copy and use this software is granted provided that itis identified as the \*(L"\s-1RSA\s0 Data Security, Inc. \s-1MD5\s0 Message-DigestAlgorithm\*(R" in all material mentioning or referencing this softwareor this function..SpLicense is also granted to make and use derivative works providedthat such works are identified as \*(L"derived from the \s-1RSA\s0 DataSecurity, Inc. \s-1MD5\s0 Message-Digest Algorithm\*(R" in all materialmentioning or referencing the derived work..Sp\&\s-1RSA\s0 Data Security, Inc. makes no representations concerning eitherthe merchantability of this software or the suitability of thissoftware for any particular purpose. It is provided \*(L"as is\*(R"without express or implied warranty of any kind..SpThese notices must be retained in any copies of any part of thisdocumentation and/or software..PPThis copyright does not prohibit distribution of any version of Perlcontaining this extension under the terms of the \s-1GNU\s0 or Artisticlicenses..SH "AUTHORS".IX Header "AUTHORS"The original \f(CW\*(C`MD5\*(C'\fR interface was written by Neil Winton(\f(CW\*(C`N.Winton@axion.bt.co.uk\*(C'\fR)..PPThe \f(CW\*(C`Digest::MD5\*(C'\fR module is written by Gisle Aas <gisle@ActiveState.com>.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -