1Crypt::Misc(3) User Contributed Perl Documentation Crypt::Misc(3)
2
3
4
6 Crypt::Misc - miscellaneous functions related to (or used by) CryptX
7
9 This module contains a collection of mostly unsorted functions loosely-
10 related to CryptX distribution but not implementing cryptography.
11
12 Most of them are also available in other perl modules but once you
13 utilize CryptX you might avoid dependencies on other modules by using
14 functions from Crypt::Misc.
15
17 use Crypt::Misc ':all';
18
19 # Base64 and Base64/URL-safe functions
20 $base64 = encode_b64($rawbytes);
21 $rawbytes = decode_b64($base64);
22 $base64url = encode_b64u($encode_b64u);
23 $rawbytes = decode_b64u($base64url);
24
25 # read/write file
26 $rawdata = read_rawfile($filename);
27 write_rawfile($filename, $rawdata);
28
29 # convert PEM/DER
30 $der_data = pem_to_der($pem_data);
31 $pem_data = der_to_pem($der_data);
32
33 # others
34 die "mismatch" unless slow_eq($str1, $str2);
35
37 By default, Crypt::Misc doesn't import any function. You can import
38 individual functions like this:
39
40 use Crypt::Misc qw(read_rawfile);
41
42 Or import all available functions:
43
44 use Crypt::Misc ':all';
45
46 read_rawfile
47 Since: 0.029
48
49 $rawdata = read_rawfile($filename);
50
51 Read file $filename into a scalar as a binary data (without
52 decoding/transformation).
53
54 write_rawfile
55 Since: 0.029
56
57 write_rawfile($filename, $rawdata);
58
59 Write $rawdata to file $filename as binary data.
60
61 slow_eq
62 Since: 0.029
63
64 if (slow_eq($data1, $data2)) { ... }
65
66 Constant time compare (to avoid timing side-channel).
67
68 pem_to_der
69 Since: 0.029
70
71 $der_data = pem_to_der($pem_data);
72 #or
73 $der_data = pem_to_der($pem_data, $password);
74
75 Convert PEM to DER representation. Supports also password protected PEM
76 data.
77
78 der_to_pem
79 Since: 0.029
80
81 $pem_data = der_to_pem($der_data, $header_name);
82 #or
83 $pem_data = der_to_pem($der_data, $header_name, $password);
84 #or
85 $pem_data = der_to_pem($der_data, $header_name, $passord, $cipher_name);
86
87 # $header_name e.g. "PUBLIC KEY", "RSA PRIVATE KEY" ...
88 # $cipher_name e.g. "DES-EDE3-CBC", "AES-256-CBC" (DEFAULT) ...
89
90 Convert DER to PEM representation. Supports also password protected PEM
91 data.
92
93 random_v4uuid
94 Since: 0.031
95
96 my $uuid = random_v4uuid();
97
98 Returns cryptographically strong Version 4 random UUID:
99 "xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx" where "x" is any hexadecimal
100 digit and "Y" is one of 8, 9, A, B (1000, 1001, 1010, 1011) e.g.
101 "f47ac10b-58cc-4372-a567-0e02b2c3d479".
102
103 is_v4uuid
104 Since: 0.031
105
106 if (is_v4uuid($uuid)) {
107 ...
108 }
109
110 Checks the given $uuid string whether it matches V4 UUID format and
111 returns 0 (mismatch) or 1 (match).
112
113 increment_octets_le
114 Since: 0.048
115
116 $octects = increment_octets_le($octets);
117
118 Take input $octets as a little-endian big number and return an
119 increment.
120
121 increment_octets_be
122 Since: 0.048
123
124 $octects = increment_octets_be($octets);
125
126 Take input $octets as a big-endian big number and return an increment.
127
128 encode_b64
129 Since: 0.029
130
131 $base64string = encode_b64($rawdata);
132
133 Encode $rawbytes into Base64 string, no line-endings in the output
134 string.
135
136 decode_b64
137 Since: 0.029
138
139 $rawdata = decode_b64($base64string);
140
141 Decode a Base64 string.
142
143 encode_b64u
144 Since: 0.029
145
146 $base64url_string = encode_b64($rawdata);
147
148 Encode $rawbytes into Base64/URL-Safe string, no line-endings in the
149 output string.
150
151 decode_b64u
152 Since: 0.029
153
154 $rawdata = decode_b64($base64url_string);
155
156 Decode a Base64/URL-Safe string.
157
158 encode_b32r
159 Since: 0.049
160
161 $string = encode_b32r($rawdata);
162
163 Encode bytes into Base32 (rfc4648 alphabet) string, without "="
164 padding.
165
166 decode_b32r
167 Since: 0.049
168
169 $rawdata = decode_b32r($string);
170
171 Decode a Base32 (rfc4648 alphabet) string into bytes.
172
173 encode_b32b
174 Since: 0.049
175
176 $string = encode_b32b($rawdata);
177
178 Encode bytes into Base32 (base32hex alphabet) string, without "="
179 padding.
180
181 decode_b32b
182 Since: 0.049
183
184 $rawdata = decode_b32b($string);
185
186 Decode a Base32 (base32hex alphabet) string into bytes.
187
188 encode_b32z
189 Since: 0.049
190
191 $string = encode_b32z($rawdata);
192
193 Encode bytes into Base32 (zbase32 alphabet) string.
194
195 decode_b32z
196 Since: 0.049
197
198 $rawdata = decode_b32z($string);
199
200 Decode a Base32 (zbase32 alphabet) string into bytes.
201
202 encode_b32c
203 Since: 0.049
204
205 $string = encode_b32c($rawdata);
206
207 Encode bytes into Base32 (crockford alphabet) string.
208
209 decode_b32c
210 Since: 0.049
211
212 $rawdata = decode_b32c($string);
213
214 Decode a Base32 (crockford alphabet) string into bytes.
215
216 encode_b58b
217 Since: 0.049
218
219 $string = encode_b58b($rawdata);
220
221 Encode bytes into Base58 (Bitcoin alphabet) string.
222
223 decode_b58b
224 Since: 0.049
225
226 $rawdata = decode_b58b($string);
227
228 Decode a Base58 (Bitcoin alphabet) string into bytes.
229
230 encode_b58f
231 Since: 0.049
232
233 $string = encode_b58f($rawdata);
234
235 Encode bytes into Base58 (Flickr alphabet) string.
236
237 decode_b58f
238 Since: 0.049
239
240 $rawdata = decode_b58f($string);
241
242 Decode a Base58 (Flickr alphabet) string into bytes.
243
244 encode_b58r
245 Since: 0.049
246
247 $string = encode_b58r($rawdata);
248
249 Encode bytes into Base58 (Ripple alphabet) string.
250
251 decode_b58r
252 Since: 0.049
253
254 $rawdata = decode_b58r($string);
255
256 Decode a Base58 (Ripple alphabet) string into bytes.
257
258 encode_b58t
259 Since: 0.049
260
261 $string = encode_b58t($rawdata);
262
263 Encode bytes into Base58 (Tipple alphabet) string.
264
265 decode_b58t
266 Since: 0.049
267
268 $rawdata = decode_b58t($string);
269
270 Decode a Base58 (Tipple alphabet) string into bytes.
271
272 encode_b58s
273 Since: 0.049
274
275 $string = encode_b58s($rawdata);
276
277 Encode bytes into Base58 (Stellar alphabet) string.
278
279 decode_b58s
280 Since: 0.049
281
282 $rawdata = decode_b58s($string);
283
284 Decode a Base58 (Stellar alphabet) string into bytes.
285
287 • CryptX
288
289
290
291perl v5.36.0 2022-07-22 Crypt::Misc(3)