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 3" | |
132 | .TH Digest 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | Digest:: \- Modules that calculate message digests | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 2 | |
138 | \& $md2 = Digest->MD2; | |
139 | \& $md5 = Digest->MD5; | |
140 | .Ve | |
141 | .PP | |
142 | .Vb 2 | |
143 | \& $sha1 = Digest->SHA1; | |
144 | \& $sha1 = Digest->new("SHA-1"); | |
145 | .Ve | |
146 | .PP | |
147 | .Vb 1 | |
148 | \& $hmac = Digest->HMAC_MD5($key); | |
149 | .Ve | |
150 | .SH "DESCRIPTION" | |
151 | .IX Header "DESCRIPTION" | |
152 | The \f(CW\*(C`Digest::\*(C'\fR modules calculate digests, also called \*(L"fingerprints\*(R" | |
153 | or \*(L"hashes\*(R", of some data, called a message. The digest is (usually) | |
154 | some small/fixed size string. The actual size of the digest depend of | |
155 | the algorithm used. The message is simply a sequence of arbitrary | |
156 | bytes. | |
157 | .PP | |
158 | An important property of the digest algorithms is that the digest is | |
159 | \&\fIlikely\fR to change if the message change in some way. Another | |
160 | property is that digest functions are one-way functions, i.e. it | |
161 | should be \fIhard\fR to find a message that correspond to some given | |
162 | digest. Algorithms differ in how \*(L"likely\*(R" and how \*(L"hard\*(R", as well as | |
163 | how efficient they are to compute. | |
164 | .PP | |
165 | All \f(CW\*(C`Digest::\*(C'\fR modules provide the same programming interface. A | |
166 | functional interface for simple use, as well as an object oriented | |
167 | interface that can handle messages of arbitrary length and which can | |
168 | read files directly. | |
169 | .PP | |
170 | The digest can be delivered in three formats: | |
171 | .IP "\fIbinary\fR" 8 | |
172 | .IX Item "binary" | |
173 | This is the most compact form, but it is not well suited for printing | |
174 | or embedding in places that can't handle arbitrary data. | |
175 | .IP "\fIhex\fR" 8 | |
176 | .IX Item "hex" | |
177 | A twice as long string of (lowercase) hexadecimal digits. | |
178 | .IP "\fIbase64\fR" 8 | |
179 | .IX Item "base64" | |
180 | A string of portable printable characters. This is the base64 encoded | |
181 | representation of the digest with any trailing padding removed. The | |
182 | string will be about 30% longer than the binary version. | |
183 | MIME::Base64 tells you more about this encoding. | |
184 | .PP | |
185 | The functional interface is simply importable functions with the same | |
186 | name as the algorithm. The functions take the message as argument and | |
187 | return the digest. Example: | |
188 | .PP | |
189 | .Vb 2 | |
190 | \& use Digest::MD5 qw(md5); | |
191 | \& $digest = md5($message); | |
192 | .Ve | |
193 | .PP | |
194 | There are also versions of the functions with \*(L"_hex\*(R" or \*(L"_base64\*(R" | |
195 | appended to the name, which returns the digest in the indicated form. | |
196 | .SH "OO INTERFACE" | |
197 | .IX Header "OO INTERFACE" | |
198 | The following methods are available for all \f(CW\*(C`Digest::\*(C'\fR modules: | |
199 | .IP "$ctx = Digest\->\s-1XXX\s0($arg,...)" 4 | |
200 | .IX Item "$ctx = Digest->XXX($arg,...)" | |
201 | .PD 0 | |
202 | .ie n .IP "$ctx = Digest\->new(\s-1XXX\s0 => $arg,...)" 4 | |
203 | .el .IP "$ctx = Digest\->new(\s-1XXX\s0 => \f(CW$arg\fR,...)" 4 | |
204 | .IX Item "$ctx = Digest->new(XXX => $arg,...)" | |
205 | .IP "$ctx = Digest::XXX\->new($arg,...)" 4 | |
206 | .IX Item "$ctx = Digest::XXX->new($arg,...)" | |
207 | .PD | |
208 | The constructor returns some object that encapsulate the state of the | |
209 | message-digest algorithm. You can add data to the object and finally | |
210 | ask for the digest. The \*(L"\s-1XXX\s0\*(R" should of course be replaced by the proper | |
211 | name of the digest algorithm you want to use. | |
212 | .Sp | |
213 | The two first forms are simply syntactic sugar which automatically | |
214 | load the right module on first use. The second form allow you to use | |
215 | algorithm names which contains letters which are not legal perl | |
216 | identifiers, e.g. \*(L"\s-1SHA\-1\s0\*(R". | |
217 | .Sp | |
218 | If \fInew()\fR is called as an instance method (i.e. \f(CW$ctx\fR\->new) it will just | |
219 | reset the state the object to the state of a newly created object. No | |
220 | new object is created in this case, and the return value is the | |
221 | reference to the object (i.e. \f(CW$ctx\fR). | |
222 | .IP "$ctx\->reset" 4 | |
223 | .IX Item "$ctx->reset" | |
224 | This is just an alias for \f(CW$ctx\fR\->new. | |
225 | .IP "$ctx\->add($data,...)" 4 | |
226 | .IX Item "$ctx->add($data,...)" | |
227 | The \f(CW$data\fR provided as argument are appended to the message we | |
228 | calculate the digest for. The return value is the \f(CW$ctx\fR object itself. | |
229 | .IP "$ctx\->addfile($io_handle)" 4 | |
230 | .IX Item "$ctx->addfile($io_handle)" | |
231 | The \f(CW$io_handle\fR is read until \s-1EOF\s0 and the content is appended to the | |
232 | message we calculate the digest for. The return value is the \f(CW$ctx\fR | |
233 | object itself. | |
234 | .IP "$ctx\->digest" 4 | |
235 | .IX Item "$ctx->digest" | |
236 | Return the binary digest for the message. | |
237 | .Sp | |
238 | Note that the \f(CW\*(C`digest\*(C'\fR operation is effectively a destructive, | |
239 | read-once operation. Once it has been performed, the \f(CW$ctx\fR object is | |
240 | automatically \f(CW\*(C`reset\*(C'\fR and can be used to calculate another digest | |
241 | value. | |
242 | .IP "$ctx\->hexdigest" 4 | |
243 | .IX Item "$ctx->hexdigest" | |
244 | Same as \f(CW$ctx\fR\->digest, but will return the digest in hexadecimal form. | |
245 | .IP "$ctx\->b64digest" 4 | |
246 | .IX Item "$ctx->b64digest" | |
247 | Same as \f(CW$ctx\fR\->digest, but will return the digest as a base64 encoded | |
248 | string. | |
249 | .SH "SEE ALSO" | |
250 | .IX Header "SEE ALSO" | |
251 | Digest::MD5, Digest::SHA1, Digest::HMAC, Digest::MD2 | |
252 | .PP | |
253 | MIME::Base64 | |
254 | .SH "AUTHOR" | |
255 | .IX Header "AUTHOR" | |
256 | Gisle Aas <gisle@aas.no> | |
257 | .PP | |
258 | The \f(CW\*(C`Digest::\*(C'\fR interface is based on the interface originally | |
259 | developed by Neil Winton for his \f(CW\*(C`MD5\*(C'\fR module. |