6 | 6 |
use Carp 'croak';
|
7 | 7 |
our %EXPORT_TAGS = ( all => [qw(encode_b64 decode_b64 encode_b64u decode_b64u pem_to_der der_to_pem read_rawfile write_rawfile slow_eq)] );
|
8 | 8 |
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
9 | |
our @EXPORT = qw();
|
|
9 |
our @EXPORT = qw();
|
10 | 10 |
|
11 | 11 |
use Carp 'carp';
|
12 | 12 |
use CryptX;
|
|
160 | 160 |
|
161 | 161 |
=head1 SYNOPSIS
|
162 | 162 |
|
|
163 |
This module contains a collection of mostly unsorted functions loosely-related to CryptX distribution but not implementing cryptography.
|
|
164 |
|
|
165 |
Most of them are also available in other perl modules but once you utilize CryptX you might avoid dependencies on other modules by using
|
|
166 |
functions from Crypt::Misc.
|
|
167 |
|
|
168 |
=head1 DESCRIPTION
|
|
169 |
|
163 | 170 |
use Crypt::Misc ':all';
|
164 | 171 |
|
165 | |
|
166 | |
=head1 DESCRIPTION
|
167 | |
|
168 | |
xxx
|
169 | |
|
170 | |
=head1 METHODS
|
|
172 |
# Base64 and Base64/URL-safe functions
|
|
173 |
$base64 = encode_b64($rawbytes);
|
|
174 |
$rawbytes = decode_b64($base64);
|
|
175 |
$base64url = encode_b64u($encode_b64u);
|
|
176 |
$rawbytes = decode_b64u($base64url);
|
|
177 |
|
|
178 |
# read/write file
|
|
179 |
$rawdata = read_rawfile($filename);
|
|
180 |
write_rawfile($filename, $rawdata);
|
|
181 |
|
|
182 |
# convert PEM/DER
|
|
183 |
$der_data = pem_to_der($pem_data);
|
|
184 |
$pem_data = der_to_pem($der_data);
|
|
185 |
|
|
186 |
# others
|
|
187 |
die "mismatch" unless slow_eq($str1, $str2);
|
|
188 |
|
|
189 |
=head1 FUNCTIONS
|
|
190 |
|
|
191 |
By default, Crypt::Misc doesn't import any function. You can import individual functions like this:
|
|
192 |
|
|
193 |
use Crypt::Misc qw(read_rawfile);
|
|
194 |
|
|
195 |
Or import all available functions:
|
|
196 |
|
|
197 |
use Crypt::Misc ':all';
|
171 | 198 |
|
172 | 199 |
=head2 encode_b64
|
173 | 200 |
|
174 | |
xxx
|
|
201 |
I<Since: CryptX-0.029>
|
|
202 |
|
|
203 |
$base64string = encode_b64($rawdata);
|
|
204 |
|
|
205 |
Encode $rawbytes into Base64 string, no line-endings in the output string.
|
175 | 206 |
|
176 | 207 |
=head2 decode_b64
|
177 | 208 |
|
178 | |
xxx
|
|
209 |
I<Since: CryptX-0.029>
|
|
210 |
|
|
211 |
$rawdata = encode_b64($base64string);
|
|
212 |
|
|
213 |
Decode a Base64 string.
|
|
214 |
|
|
215 |
=head2 encode_b64u
|
|
216 |
|
|
217 |
I<Since: CryptX-0.029>
|
|
218 |
|
|
219 |
$base64url_string = encode_b64($rawdata);
|
|
220 |
|
|
221 |
Encode $rawbytes into Base64/URL-Safe string, no line-endings in the output string.
|
|
222 |
|
|
223 |
=head2 decode_b64u
|
|
224 |
|
|
225 |
I<Since: CryptX-0.029>
|
|
226 |
|
|
227 |
$rawdata = encode_b64($base64url_string);
|
|
228 |
|
|
229 |
Decode a Base64/URL-Safe string.
|
179 | 230 |
|
180 | 231 |
=head2 read_rawfile
|
181 | 232 |
|
182 | |
xxx
|
|
233 |
I<Since: CryptX-0.029>
|
|
234 |
|
|
235 |
$rawdata = read_rawfile($filename);
|
|
236 |
|
|
237 |
Read file C<$filename> into a scalar as a binary data (without decoding/transformation).
|
183 | 238 |
|
184 | 239 |
=head2 write_rawfile
|
185 | 240 |
|
186 | |
xxx
|
|
241 |
I<Since: CryptX-0.029>
|
|
242 |
|
|
243 |
write_rawfile($filename, $rawdata);
|
|
244 |
|
|
245 |
Write C<$rawdata> to file <$filename> as binary data.
|
187 | 246 |
|
188 | 247 |
=head2 slow_eq
|
189 | 248 |
|
190 | |
xxx
|
191 | |
|
192 | |
=head2 encode_b64u
|
193 | |
|
194 | |
xxx
|
195 | |
|
196 | |
=head2 decode_b64u
|
197 | |
|
198 | |
xxx
|
|
249 |
I<Since: CryptX-0.029>
|
|
250 |
|
|
251 |
if (slow_eq($data1, $data2)) { ... }
|
|
252 |
|
|
253 |
Constant time compare (to avoid timing side-channel).
|
199 | 254 |
|
200 | 255 |
=head2 pem_to_der
|
201 | 256 |
|
202 | |
xxx
|
|
257 |
I<Since: CryptX-0.029>
|
|
258 |
|
|
259 |
$der_data = pem_to_der($pem_data);
|
|
260 |
#or
|
|
261 |
$der_data = pem_to_der($pem_data, $password);
|
|
262 |
|
|
263 |
Convert PEM to DER representation. Supports also password protected PEM data.
|
203 | 264 |
|
204 | 265 |
=head2 der_to_pem
|
205 | 266 |
|
206 | |
xxx
|
|
267 |
I<Since: CryptX-0.029>
|
|
268 |
|
|
269 |
$pem_data = der_to_pem($pem_data, $header_name);
|
|
270 |
#or
|
|
271 |
$pem_data = der_to_pem($pem_data, $header_name, $password);
|
|
272 |
#or
|
|
273 |
$pem_data = der_to_pem($pem_data, $header_name, $passord, $cipher_name);
|
|
274 |
|
|
275 |
# $header_name e.g. "PUBLIC KEY", "RSA PRIVATE KEY" ...
|
|
276 |
# $cipher_name e.g. "DES-EDE3-CBC", "AES-256-CBC" (DEFAULT) ...
|
|
277 |
|
|
278 |
Convert DER to PEM representation. Supports also password protected PEM data.
|
207 | 279 |
|
208 | 280 |
=head1 SEE ALSO
|
209 | 281 |
|
|
214 | 286 |
=back
|
215 | 287 |
|
216 | 288 |
=cut
|
217 | |
|
218 | |
__END__
|