1Crypt::Digest::MD5(3) User Contributed Perl DocumentationCrypt::Digest::MD5(3)
2
3
4
6 Crypt::Digest::MD5 - Hash function MD5 [size: 128 bits]
7
9 ### Functional interface:
10 use Crypt::Digest::MD5 qw( md5 md5_hex md5_b64 md5_b64u
11 md5_file md5_file_hex md5_file_b64 md5_file_b64u );
12
13 # calculate digest from string/buffer
14 $md5_raw = md5('data string');
15 $md5_hex = md5_hex('data string');
16 $md5_b64 = md5_b64('data string');
17 $md5_b64u = md5_b64u('data string');
18 # calculate digest from file
19 $md5_raw = md5_file('filename.dat');
20 $md5_hex = md5_file_hex('filename.dat');
21 $md5_b64 = md5_file_b64('filename.dat');
22 $md5_b64u = md5_file_b64u('filename.dat');
23 # calculate digest from filehandle
24 $md5_raw = md5_file(*FILEHANDLE);
25 $md5_hex = md5_file_hex(*FILEHANDLE);
26 $md5_b64 = md5_file_b64(*FILEHANDLE);
27 $md5_b64u = md5_file_b64u(*FILEHANDLE);
28
29 ### OO interface:
30 use Crypt::Digest::MD5;
31
32 $d = Crypt::Digest::MD5->new;
33 $d->add('any data');
34 $d->addfile('filename.dat');
35 $d->addfile(*FILEHANDLE);
36 $result_raw = $d->digest; # raw bytes
37 $result_hex = $d->hexdigest; # hexadecimal form
38 $result_b64 = $d->b64digest; # Base64 form
39 $result_b64u = $d->b64udigest; # Base64 URL Safe form
40
42 Provides an interface to the MD5 digest algorithm.
43
45 Nothing is exported by default.
46
47 You can export selected functions:
48
49 use Crypt::Digest::MD5 qw(md5 md5_hex md5_b64 md5_b64u
50 md5_file md5_file_hex md5_file_b64 md5_file_b64u);
51
52 Or all of them at once:
53
54 use Crypt::Digest::MD5 ':all';
55
57 md5
58 Logically joins all arguments into a single string, and returns its MD5
59 digest encoded as a binary string.
60
61 $md5_raw = md5('data string');
62 #or
63 $md5_raw = md5('any data', 'more data', 'even more data');
64
65 md5_hex
66 Logically joins all arguments into a single string, and returns its MD5
67 digest encoded as a hexadecimal string.
68
69 $md5_hex = md5_hex('data string');
70 #or
71 $md5_hex = md5_hex('any data', 'more data', 'even more data');
72
73 md5_b64
74 Logically joins all arguments into a single string, and returns its MD5
75 digest encoded as a Base64 string, with trailing '=' padding.
76
77 $md5_b64 = md5_b64('data string');
78 #or
79 $md5_b64 = md5_b64('any data', 'more data', 'even more data');
80
81 md5_b64u
82 Logically joins all arguments into a single string, and returns its MD5
83 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
84
85 $md5_b64url = md5_b64u('data string');
86 #or
87 $md5_b64url = md5_b64u('any data', 'more data', 'even more data');
88
89 md5_file
90 Reads file (defined by filename or filehandle) content, and returns its
91 MD5 digest encoded as a binary string.
92
93 $md5_raw = md5_file('filename.dat');
94 #or
95 $md5_raw = md5_file(*FILEHANDLE);
96
97 md5_file_hex
98 Reads file (defined by filename or filehandle) content, and returns its
99 MD5 digest encoded as a hexadecimal string.
100
101 $md5_hex = md5_file_hex('filename.dat');
102 #or
103 $md5_hex = md5_file_hex(*FILEHANDLE);
104
105 BEWARE: You have to make sure that the filehandle is in binary mode
106 before you pass it as argument to the addfile() method.
107
108 md5_file_b64
109 Reads file (defined by filename or filehandle) content, and returns its
110 MD5 digest encoded as a Base64 string, with trailing '=' padding.
111
112 $md5_b64 = md5_file_b64('filename.dat');
113 #or
114 $md5_b64 = md5_file_b64(*FILEHANDLE);
115
116 md5_file_b64u
117 Reads file (defined by filename or filehandle) content, and returns its
118 MD5 digest encoded as a Base64 URL Safe string (see RFC 4648 section
119 5).
120
121 $md5_b64url = md5_file_b64u('filename.dat');
122 #or
123 $md5_b64url = md5_file_b64u(*FILEHANDLE);
124
126 The OO interface provides the same set of functions as Crypt::Digest.
127
128 new
129 $d = Crypt::Digest::MD5->new();
130
131 clone
132 $d->clone();
133
134 reset
135 $d->reset();
136
137 add
138 $d->add('any data');
139 #or
140 $d->add('any data', 'more data', 'even more data');
141
142 addfile
143 $d->addfile('filename.dat');
144 #or
145 $d->addfile(*FILEHANDLE);
146
147 add_bits
148 $d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
149 #or
150 $d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
151
152 hashsize
153 $d->hashsize;
154 #or
155 Crypt::Digest::MD5->hashsize();
156 #or
157 Crypt::Digest::MD5::hashsize();
158
159 digest
160 $result_raw = $d->digest();
161
162 hexdigest
163 $result_hex = $d->hexdigest();
164
165 b64digest
166 $result_b64 = $d->b64digest();
167
168 b64udigest
169 $result_b64url = $d->b64udigest();
170
172 · CryptX, Crypt::Digest
173
174 · <http://en.wikipedia.org/wiki/MD5>
175
176
177
178perl v5.30.0 2019-07-26 Crypt::Digest::MD5(3)