Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "Digest::MD5 3" | |
132 | .TH Digest::MD5 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | Digest::MD5 \- Perl interface to the MD5 Algorithm | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 2 | |
138 | \& # Functional style | |
139 | \& use Digest::MD5 qw(md5 md5_hex md5_base64); | |
140 | .Ve | |
141 | .PP | |
142 | .Vb 3 | |
143 | \& $digest = md5($data); | |
144 | \& $digest = md5_hex($data); | |
145 | \& $digest = md5_base64($data); | |
146 | .Ve | |
147 | .PP | |
148 | .Vb 2 | |
149 | \& # OO style | |
150 | \& use Digest::MD5; | |
151 | .Ve | |
152 | .PP | |
153 | .Vb 1 | |
154 | \& $ctx = Digest::MD5->new; | |
155 | .Ve | |
156 | .PP | |
157 | .Vb 2 | |
158 | \& $ctx->add($data); | |
159 | \& $ctx->addfile(*FILE); | |
160 | .Ve | |
161 | .PP | |
162 | .Vb 3 | |
163 | \& $digest = $ctx->digest; | |
164 | \& $digest = $ctx->hexdigest; | |
165 | \& $digest = $ctx->b64digest; | |
166 | .Ve | |
167 | .SH "DESCRIPTION" | |
168 | .IX Header "DESCRIPTION" | |
169 | The \f(CW\*(C`Digest::MD5\*(C'\fR module allows you to use the \s-1RSA\s0 Data Security | |
170 | Inc. \s-1MD5\s0 Message Digest algorithm from within Perl programs. The | |
171 | algorithm takes as input a message of arbitrary length and produces as | |
172 | output a 128\-bit \*(L"fingerprint\*(R" or \*(L"message digest\*(R" of the input. | |
173 | .PP | |
174 | The \f(CW\*(C`Digest::MD5\*(C'\fR module provide a procedural interface for simple | |
175 | use, as well as an object oriented interface that can handle messages | |
176 | of arbitrary length and which can read files directly. | |
177 | .PP | |
178 | A binary digest will be 16 bytes long. A hex digest will be 32 | |
179 | characters long. A base64 digest will be 22 characters long. | |
180 | .SH "FUNCTIONS" | |
181 | .IX Header "FUNCTIONS" | |
182 | The following functions can be exported from the \f(CW\*(C`Digest::MD5\*(C'\fR | |
183 | module. No functions are exported by default. | |
184 | .IP "md5($data,...)" 4 | |
185 | .IX Item "md5($data,...)" | |
186 | This function will concatenate all arguments, calculate the \s-1MD5\s0 digest | |
187 | of this \*(L"message\*(R", and return it in binary form. | |
188 | .IP "md5_hex($data,...)" 4 | |
189 | .IX Item "md5_hex($data,...)" | |
190 | Same as \fImd5()\fR, but will return the digest in hexadecimal form. | |
191 | .IP "md5_base64($data,...)" 4 | |
192 | .IX Item "md5_base64($data,...)" | |
193 | Same as \fImd5()\fR, but will return the digest as a base64 encoded string. | |
194 | .Sp | |
195 | The base64 encoded string returned is not padded to be a multiple of 4 | |
196 | bytes long. If you want interoperability with other base64 encoded | |
197 | md5 digests you might want to append the string \*(L"==\*(R" to the result. | |
198 | .SH "METHODS" | |
199 | .IX Header "METHODS" | |
200 | The following methods are available: | |
201 | .IP "$md5 = Digest::MD5\->new" 4 | |
202 | .IX Item "$md5 = Digest::MD5->new" | |
203 | The constructor returns a new \f(CW\*(C`Digest::MD5\*(C'\fR object which encapsulate | |
204 | the state of the \s-1MD5\s0 message-digest algorithm. You can add data to | |
205 | the object and finally ask for the digest. | |
206 | .Sp | |
207 | If called as an instance method (i.e. \f(CW$md5\fR\->new) it will just reset the | |
208 | state the object to the state of a newly created object. No new | |
209 | object is created in this case. | |
210 | .IP "$md5\->reset" 4 | |
211 | .IX Item "$md5->reset" | |
212 | This is just an alias for \f(CW$md5\fR\->new. | |
213 | .IP "$md5\->add($data,...)" 4 | |
214 | .IX Item "$md5->add($data,...)" | |
215 | The \f(CW$data\fR provided as argument are appended to the message we | |
216 | calculate the digest for. The return value is the \f(CW$md5\fR object itself. | |
217 | .IP "$md5\->addfile($io_handle)" 4 | |
218 | .IX Item "$md5->addfile($io_handle)" | |
219 | The \f(CW$io_handle\fR is read until \s-1EOF\s0 and the content is appended to the | |
220 | message we calculate the digest for. The return value is the \f(CW$md5\fR | |
221 | object itself. | |
222 | .Sp | |
223 | In most cases you want to make sure that the \f(CW$io_handle\fR is set up to | |
224 | be in \fIbinmode()\fR. | |
225 | .IP "$md5\->digest" 4 | |
226 | .IX Item "$md5->digest" | |
227 | Return the binary digest for the message. | |
228 | .Sp | |
229 | Note that the \f(CW\*(C`digest\*(C'\fR operation is effectively a destructive, | |
230 | read-once operation. Once it has been performed, the \f(CW\*(C`Digest::MD5\*(C'\fR | |
231 | object is automatically \f(CW\*(C`reset\*(C'\fR and can be used to calculate another | |
232 | digest value. | |
233 | .IP "$md5\->hexdigest" 4 | |
234 | .IX Item "$md5->hexdigest" | |
235 | Same as \f(CW$md5\fR\->digest, but will return the digest in hexadecimal form. | |
236 | .IP "$md5\->b64digest" 4 | |
237 | .IX Item "$md5->b64digest" | |
238 | Same as \f(CW$md5\fR\->digest, but will return the digest as a base64 encoded | |
239 | string. | |
240 | .Sp | |
241 | The base64 encoded string returned is not padded to be a multiple of 4 | |
242 | bytes long. If you want interoperability with other base64 encoded | |
243 | md5 digests you might want to append the string \*(L"==\*(R" to the result. | |
244 | .SH "EXAMPLES" | |
245 | .IX Header "EXAMPLES" | |
246 | The simplest way to use this library is to import the \fImd5_hex()\fR | |
247 | function (or one of its cousins): | |
248 | .PP | |
249 | .Vb 2 | |
250 | \& use Digest::MD5 qw(md5_hex); | |
251 | \& print "Digest is ", md5_hex("foobarbaz"), "\en"; | |
252 | .Ve | |
253 | .PP | |
254 | The above example would print out the message | |
255 | .PP | |
256 | .Vb 1 | |
257 | \& Digest is 6df23dc03f9b54cc38a0fc1483df6e21 | |
258 | .Ve | |
259 | .PP | |
260 | provided that the implementation is working correctly. The same | |
261 | checksum can also be calculated in \s-1OO\s0 style: | |
262 | .PP | |
263 | .Vb 1 | |
264 | \& use Digest::MD5; | |
265 | .Ve | |
266 | .PP | |
267 | .Vb 4 | |
268 | \& $md5 = Digest::MD5->new; | |
269 | \& $md5->add('foo', 'bar'); | |
270 | \& $md5->add('baz'); | |
271 | \& $digest = $md5->hexdigest; | |
272 | .Ve | |
273 | .PP | |
274 | .Vb 1 | |
275 | \& print "Digest is $digest\en"; | |
276 | .Ve | |
277 | .PP | |
278 | With \s-1OO\s0 style you can break the message arbitrary. This means that we | |
279 | are no longer limited to have space for the whole message in memory, i.e. | |
280 | we can handle messages of any size. | |
281 | .PP | |
282 | This is useful when calculating checksum for files: | |
283 | .PP | |
284 | .Vb 1 | |
285 | \& use Digest::MD5; | |
286 | .Ve | |
287 | .PP | |
288 | .Vb 3 | |
289 | \& my $file = shift || "/etc/passwd"; | |
290 | \& open(FILE, $file) or die "Can't open '$file': $!"; | |
291 | \& binmode(FILE); | |
292 | .Ve | |
293 | .PP | |
294 | .Vb 6 | |
295 | \& $md5 = Digest::MD5->new; | |
296 | \& while (<FILE>) { | |
297 | \& $md5->add($_); | |
298 | \& } | |
299 | \& close(FILE); | |
300 | \& print $md5->b64digest, " $file\en"; | |
301 | .Ve | |
302 | .PP | |
303 | Or we can use the builtin addfile method for more efficient reading of | |
304 | the file: | |
305 | .PP | |
306 | .Vb 1 | |
307 | \& use Digest::MD5; | |
308 | .Ve | |
309 | .PP | |
310 | .Vb 3 | |
311 | \& my $file = shift || "/etc/passwd"; | |
312 | \& open(FILE, $file) or die "Can't open '$file': $!"; | |
313 | \& binmode(FILE); | |
314 | .Ve | |
315 | .PP | |
316 | .Vb 1 | |
317 | \& print Digest::MD5->new->addfile(*FILE)->hexdigest, " $file\en"; | |
318 | .Ve | |
319 | .SH "SEE ALSO" | |
320 | .IX Header "SEE ALSO" | |
321 | Digest, | |
322 | Digest::MD2, | |
323 | Digest::SHA1, | |
324 | Digest::HMAC | |
325 | .PP | |
326 | \&\fImd5sum\fR\|(1) | |
327 | .PP | |
328 | \&\s-1RFC\s0 1321 | |
329 | .SH "COPYRIGHT" | |
330 | .IX Header "COPYRIGHT" | |
331 | This library is free software; you can redistribute it and/or | |
332 | modify it under the same terms as Perl itself. | |
333 | .PP | |
334 | .Vb 3 | |
335 | \& Copyright 1998-2002 Gisle Aas. | |
336 | \& Copyright 1995-1996 Neil Winton. | |
337 | \& Copyright 1991-1992 RSA Data Security, Inc. | |
338 | .Ve | |
339 | .PP | |
340 | The \s-1MD5\s0 algorithm is defined in \s-1RFC\s0 1321. The basic C code | |
341 | implementing the algorithm is derived from that in the \s-1RFC\s0 and is | |
342 | covered by the following copyright: | |
343 | .IP "\(bu" 4 | |
344 | Copyright (C) 1991\-2, \s-1RSA\s0 Data Security, Inc. Created 1991. All | |
345 | rights reserved. | |
346 | .Sp | |
347 | License to copy and use this software is granted provided that it | |
348 | is identified as the \*(L"\s-1RSA\s0 Data Security, Inc. \s-1MD5\s0 Message-Digest | |
349 | Algorithm\*(R" in all material mentioning or referencing this software | |
350 | or this function. | |
351 | .Sp | |
352 | License is also granted to make and use derivative works provided | |
353 | that such works are identified as \*(L"derived from the \s-1RSA\s0 Data | |
354 | Security, Inc. \s-1MD5\s0 Message-Digest Algorithm\*(R" in all material | |
355 | mentioning or referencing the derived work. | |
356 | .Sp | |
357 | \&\s-1RSA\s0 Data Security, Inc. makes no representations concerning either | |
358 | the merchantability of this software or the suitability of this | |
359 | software for any particular purpose. It is provided \*(L"as is\*(R" | |
360 | without express or implied warranty of any kind. | |
361 | .Sp | |
362 | These notices must be retained in any copies of any part of this | |
363 | documentation and/or software. | |
364 | .PP | |
365 | This copyright does not prohibit distribution of any version of Perl | |
366 | containing this extension under the terms of the \s-1GNU\s0 or Artistic | |
367 | licenses. | |
368 | .SH "AUTHORS" | |
369 | .IX Header "AUTHORS" | |
370 | The original \s-1MD5\s0 interface was written by Neil Winton | |
371 | (\f(CW\*(C`N.Winton@axion.bt.co.uk\*(C'\fR). | |
372 | .PP | |
373 | This release was made by Gisle Aas <gisle@ActiveState.com> |