File Coverage

blib/lib/Crypt/Misc.pm
Criterion Covered Total %
statement 181 181 100.0
branch 68 88 77.2
condition 24 37 64.8
subroutine 34 34 100.0
pod 18 18 100.0
total 325 358 90.7


line stmt bran cond sub pod time code
1             package Crypt::Misc;
2              
3 22     22   159510 use strict;
  22         29  
  22         642  
4 22     22   91 use warnings;
  22         25  
  22         1343  
5             our $VERSION = '0.090';
6              
7             require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
8 22     22   87 use Carp 'croak';
  22         27  
  22         2899  
9             our %EXPORT_TAGS = ( all => [qw(encode_b64 decode_b64
10             encode_b64u decode_b64u
11             encode_b58b decode_b58b
12             encode_b58f decode_b58f
13             encode_b58r decode_b58r
14             encode_b58t decode_b58t
15             encode_b58s decode_b58s
16             encode_b32r decode_b32r
17             encode_b32b decode_b32b
18             encode_b32z decode_b32z
19             encode_b32c decode_b32c
20             pem_to_der der_to_pem
21             read_rawfile write_rawfile
22             slow_eq is_v4uuid random_v4uuid
23             is_uuid random_v7uuid
24             increment_octets_be increment_octets_le
25             )] );
26             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
27             our @EXPORT = qw();
28              
29 22     22   903 use CryptX;
  22         36  
  22         467  
30 22     22   4073 use Crypt::Digest 'digest_data';
  22         35  
  22         960  
31 22     22   7875 use Crypt::Mode::CBC;
  22         39  
  22         536  
32 22     22   7739 use Crypt::Mode::CFB;
  22         42  
  22         519  
33 22     22   7573 use Crypt::Mode::ECB;
  22         46  
  22         524  
34 22     22   7285 use Crypt::Mode::OFB;
  22         43  
  22         496  
35 22     22   94 use Crypt::Cipher;
  22         26  
  22         289  
36 22     22   7623 use Crypt::PRNG 'random_bytes';
  22         63  
  22         1169  
37 22     22   96 use Time::HiRes (); # perl core module
  22         99  
  22         54917  
38              
39             sub _encode_b58 {
40 292     292   717 my ($bytes, $alphabet) = @_;
41              
42 292 100       801 return undef if !defined $bytes;
43 291 100       763 return '' if length($bytes) == 0;
44              
45             # handle leading zero-bytes
46 290         423 my $base58 = '';
47 290 100       1115 if ($bytes =~ /^(\x00+)/) {
48 80         425 $base58 = ('0' x length($1));
49             }
50 290         4680 $base58 .= _bin_to_radix($bytes, 58);
51              
52 290 50       770 if (defined $alphabet) {
53 290         438 my $default = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv";
54 290 50       1257 return undef if $alphabet !~ /^[a-zA-Z0-9]{58}$/;
55 290         449 my %map;
56 290         11933 @map{split //, $default} = split //, $alphabet;
57 290         2752 $base58 = join '', map { $map{$_} } split //, $base58;
  5545         12700  
58             }
59              
60 290         1651 return $base58;
61             }
62              
63             sub _decode_b58 {
64 294     294   572 my ($base58, $alphabet) = @_;
65              
66 294 100       733 return undef if !defined $base58;
67 293 100       629 return '' if length($base58) == 0;
68              
69 292         569 my $default = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv";
70 292 50       568 if (defined $alphabet) {
71 292 100 66     14497 return undef if $alphabet !~ /^[a-zA-Z0-9]{58}$/ || $base58 !~ /^[$alphabet]+$/;
72 290         781 my %map;
73 290         7606 @map{split //, $alphabet} = split //, $default;
74 290         2052 $base58 = join '', map { $map{$_} } split //, $base58;
  5545         8745  
75             }
76 290 50       2162 return undef if $base58 !~ /^[$default]+$/;
77              
78             # handle leading zeroes
79 290         430 my $bytes = '';
80 290 100       688 if ($base58 =~ /^(0+)(.*)$/) {
81 80         198 $base58 = $2;
82 80         199 $bytes = ("\x00" x length($1));
83             }
84 290 100 66     2320 $bytes .= _radix_to_bin($base58, 58) if defined $base58 && length($base58) > 0;
85              
86 290         1487 return $bytes;
87             }
88              
89 62     62 1 878 sub decode_b58b { _decode_b58(shift, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") } # Bitcoin
90 58     58 1 116 sub decode_b58f { _decode_b58(shift, "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ") } # Flickr
91 58     58 1 113 sub decode_b58r { _decode_b58(shift, "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") } # Ripple
92 58     58 1 126 sub decode_b58t { _decode_b58(shift, "RPShNAF39wBUDnEGHJKLM4pQrsT7VWXYZ2bcdeCg65jkm8ofqi1tuvaxyz") } # Tipple
93 58     58 1 121 sub decode_b58s { _decode_b58(shift, "gsphnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCr65jkm8oFqi1tuvAxyz") } # Stellar
94              
95 60     60 1 308309 sub encode_b58b { _encode_b58(shift, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") } # Bitcoin
96 58     58 1 175 sub encode_b58f { _encode_b58(shift, "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ") } # Flickr
97 58     58 1 176 sub encode_b58r { _encode_b58(shift, "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") } # Ripple
98 58     58 1 177 sub encode_b58t { _encode_b58(shift, "RPShNAF39wBUDnEGHJKLM4pQrsT7VWXYZ2bcdeCg65jkm8ofqi1tuvaxyz") } # Tipple
99 58     58 1 175 sub encode_b58s { _encode_b58(shift, "gsphnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCr65jkm8oFqi1tuvAxyz") } # Stellar
100              
101             sub pem_to_der {
102 28     28 1 1060 my ($data, $password) = @_;
103              
104 28         41 my ($begin, $obj1, $content, $end, $obj2);
105             # first try to load KEY (e.g. EC pem files might contain more parts)
106 28         239 ($begin, $obj1, $content, $end, $obj2) = $data =~ m/(----[- ]BEGIN ([^\r\n\-]+KEY)[ -]----)(.*?)(----[- ]END ([^\r\n\-]+)[ -]----)/s;
107             # if failed then try to load anything
108 28 100       97 ($begin, $obj1, $content, $end, $obj2) = $data =~ m/(----[- ]BEGIN ([^\r\n\-]+)[ -]----)(.*?)(----[- ]END ([^\r\n\-]+)[ -]----)/s unless defined $content;
109 28 50       63 return undef unless $content;
110 28 100 33     153 return undef if !defined($obj1) || !defined($obj2) || $obj1 ne $obj2;
      66        
111              
112 26         114 $content =~ s/^\s+//sg;
113 26         154 $content =~ s/\s+$//sg;
114 26         45 $content =~ s/\r\n/\n/sg; # CR-LF >> LF
115 26         40 $content =~ s/\r/\n/sg; # CR >> LF
116 26         32 $content =~ s/\\\n//sg; # \ + LF
117              
118 26         156 my ($headers, undef, $b64) = $content =~ /^(([^:]+:.*?\n)*)(.*)$/s;
119 26 50       55 return undef unless $b64;
120              
121 26         206 my $binary = decode_b64($b64);
122 26 50       45 return undef unless defined $binary;
123              
124 26         40 my ($ptype, $cipher_name, $iv_hex);
125 26   100     106 for my $h (split /\n/, ($headers||'')) {
126 20         40 my ($k, $v) = split /:\s*/, $h, 2;
127 20 100       30 $ptype = $v if $k eq 'Proc-Type';
128 20 100       68 ($cipher_name, $iv_hex) = $v =~ /^\s*(.*?)\s*,\s*([0-9a-fA-F]+)\s*$/ if $k eq 'DEK-Info';
129             }
130 26 50 66     86 if ($cipher_name && $iv_hex && $ptype && $ptype eq '4,ENCRYPTED') {
      66        
      33        
131 10 50       23 croak "FATAL: encrypted PEM but no password provided" unless defined $password;
132 10         31 my $iv = pack("H*", $iv_hex);
133 10         14 my ($mode, $klen) = _name2mode($cipher_name);
134 10         18 my $key = _password2key($password, $klen, $iv, 'MD5');
135 10         63 return $mode->decrypt($binary, $key, $iv);
136             }
137 16         51 return $binary;
138             }
139              
140             sub der_to_pem {
141 37     37 1 13013 my ($data, $header_name, $password, $cipher_name) = @_;
142 37 100 100     791 croak "FATAL: der_to_pem invalid header name" unless defined $header_name && $header_name =~ /^[0-9A-Za-z ]+$/;
143 33         43 my $content = $data;
144 33         42 my @headers;
145              
146 33 100       52 if (defined $password) {
147 9   100     19 $cipher_name ||= 'AES-256-CBC';
148 9         15 my ($mode, $klen, $ilen) = _name2mode($cipher_name);
149 9         36 my $iv = random_bytes($ilen);
150 9         20 my $key = _password2key($password, $klen, $iv, 'MD5');
151 9         26 $content = $mode->encrypt($data, $key, $iv);
152 9         81 push @headers, 'Proc-Type: 4,ENCRYPTED', "DEK-Info: ".uc($cipher_name).",".unpack("H*", $iv);
153             }
154              
155 33         47 my $pem = "-----BEGIN $header_name-----\n";
156 33 100       54 if (@headers) {
157 9         26 $pem .= "$_\n" for @headers;
158 9         8 $pem .= "\n";
159             }
160 33         411 my @l = encode_b64($content) =~ /.{1,64}/g;
161 33         99 $pem .= join("\n", @l) . "\n";
162 33         43 $pem .= "-----END $header_name-----\n";
163 33         148 return $pem;
164             }
165              
166             sub read_rawfile {
167             # $data = read_rawfile($filename);
168 297     297 1 6108 my $f = shift;
169 297 50       3024 croak "FATAL: read_rawfile() non-existing file '$f'" unless -f $f;
170 297 50       10971 open my $fh, "<", $f or croak "FATAL: read_rawfile() cannot open file '$f': $!";
171 297         792 binmode $fh;
172 297         490 return do { local $/; <$fh> };
  297         1234  
  297         15808  
173             }
174              
175             sub write_rawfile {
176             # write_rawfile($filename, $data);
177 3 50   3 1 9 croak "FATAL: write_rawfile() no data" unless defined $_[1];
178 3 50       947 open my $fh, ">", $_[0] or croak "FATAL: write_rawfile() cannot open file '$_[0]': $!";
179 3         14 binmode $fh;
180 3 50       35 print $fh $_[1] or croak "FATAL: write_rawfile() cannot write to '$_[0]': $!";
181 3 50       120 close $fh or croak "FATAL: write_rawfile() cannot close '$_[0]': $!";
182 3         18 return;
183             }
184              
185             ### slow_eq() is implemented in XS (CryptX.xs) using libtomcrypt's mem_neq()
186              
187             sub random_v4uuid() {
188             # Version 4 - random - UUID: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx
189             # where x is any hexadecimal digit and Y is one of 8, 9, A, B (1000, 1001, 1010, 1011)
190             # e.g. f47ac10b-58cc-4372-a567-0e02b2c3d479
191 1     1 1 518 my $raw = random_bytes(16);
192             # xxxxxxxxxxxx4xxxYxxxxxxxxxxxxxxx
193 1         2 $raw &= pack("H*", "FFFFFFFFFFFF0FFFFFFFFFFFFFFFFFFF");
194 1         3 $raw |= pack("H*", "00000000000040000000000000000000");
195 1         1 $raw &= pack("H*", "FFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF"); # 0x3 == 0011b
196 1         2 $raw |= pack("H*", "00000000000000008000000000000000"); # 0x8 == 1000b
197 1         3 my $hex = unpack("H*", $raw);
198 1         14 $hex =~ s/^(.{8})(.{4})(.{4})(.{4})(.{12}).*$/$1-$2-$3-$4-$5/;
199 1         3 return $hex;
200             }
201              
202             sub random_v7uuid() {
203             # RFC 9562 §5.7 - Version 7 UUID (time-ordered)
204             # Format: xxxxxxxx-xxxx-7xxx-[89ab]xxx-xxxxxxxxxxxx
205             # Structure: 48-bit ms timestamp | 4-bit ver=7 | 12-bit rand | 2-bit var=10 | 62-bit rand
206 3     3 1 10 my ($sec, $usec) = Time::HiRes::gettimeofday();
207 3         6 my $ms = $sec * 1000 + int($usec / 1000);
208 3         7 my $rand = random_bytes(10);
209 3         22 my $raw = pack("N", int($ms / 65536)) . # bytes 0-3: ms[47:16]
210             pack("n", $ms % 65536) . # bytes 4-5: ms[15:0]
211             pack("n", 0x7000 | (unpack("n", substr($rand, 0, 2)) & 0x0FFF)) . # bytes 6-7: ver=7 + rand_a
212             pack("C", 0x80 | (unpack("C", substr($rand, 2, 1)) & 0x3F)) . # byte 8: var=10 + rand_b
213             substr($rand, 3, 7); # bytes 9-15: rand_b (cont.)
214 3         5 my $hex = unpack("H*", $raw);
215 3         24 $hex =~ s/^(.{8})(.{4})(.{4})(.{4})(.{12})$/$1-$2-$3-$4-$5/;
216 3         8 return $hex;
217             }
218              
219             sub is_v4uuid($) {
220 5     5 1 222 my $uuid = shift;
221 5 50       10 return 0 if !$uuid;
222 5 100       25 return 1 if $uuid =~ /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
223 3         8 return 0;
224             }
225              
226             sub is_uuid($) {
227 11     11 1 1290 my $uuid = shift;
228 11 100       21 return 0 if !$uuid;
229 10 100       50 return 1 if $uuid =~ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
230 4         54 return 0;
231             }
232              
233             ### private functions
234              
235             sub _name2mode {
236 20     20   635 my $cipher_name = uc(shift);
237 20         45 my %trans = ( 'DES-EDE3' => 'DES_EDE' );
238              
239 20         99 my ($cipher, undef, $klen, $mode) = $cipher_name =~ /^(AES|CAMELLIA|DES|DES-EDE3|SEED)(-(\d+))?-(CBC|CFB|ECB|OFB)$/i;
240 20 100 66     156 croak "FATAL: unsupported cipher '$cipher_name'" unless $cipher && $mode;
241 19   66     42 $cipher = $trans{$cipher} || $cipher;
242 19 100       41 $klen = 192 if $cipher eq 'DES_EDE';
243 19 100       43 $klen = 64 if $cipher eq 'DES';
244 19 100       26 $klen = 128 if $cipher eq 'SEED';
245 19 50       46 $klen = $klen ? int($klen/8) : Crypt::Cipher::min_keysize($cipher);
246 19         75 my $ilen = Crypt::Cipher::blocksize($cipher);
247 19 50 33     45 croak "FATAL: unsupported cipher '$cipher_name'" unless $klen && $ilen;
248              
249 19 100       192 return (Crypt::Mode::CBC->new($cipher), $klen, $ilen) if $mode eq 'CBC';
250 4 100       20 return (Crypt::Mode::CFB->new($cipher), $klen, $ilen) if $mode eq 'CFB';
251 2 50       3 return (Crypt::Mode::ECB->new($cipher), $klen, $ilen) if $mode eq 'ECB';
252 2 50       46 return (Crypt::Mode::OFB->new($cipher), $klen, $ilen) if $mode eq 'OFB';
253             }
254              
255             sub _password2key {
256 19     19   32 my ($password, $klen, $iv, $hash) = @_;
257 19         28 my $salt = substr($iv, 0, 8);
258 19         19 my $key = '';
259 19         26 while (length($key) < $klen) {
260 32         146 $key .= digest_data($hash, $key . $password . $salt);
261             }
262 19         34 return substr($key, 0, $klen);
263             }
264              
265             1;
266              
267             =pod
268              
269             =head1 NAME
270              
271             Crypt::Misc - miscellaneous functions related to (or used by) CryptX
272              
273             =head1 SYNOPSIS
274              
275             use Crypt::Misc ':all';
276              
277             my $rawbytes = 'hello world';
278             my $filename = 'sample.bin';
279             my $pem_data = "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----\n";
280             my $str1 = 'same';
281             my $str2 = 'same';
282              
283             # Base64 and Base64 URL-safe functions
284             my $base64 = encode_b64($rawbytes);
285             my $rawbytes2 = decode_b64($base64);
286             my $base64url = encode_b64u($rawbytes);
287             my $rawbytes3 = decode_b64u($base64url);
288              
289             # read/write file
290             my $rawdata = read_rawfile($filename);
291             write_rawfile($filename, $rawdata);
292              
293             # convert PEM/DER
294             my $der_data = pem_to_der($pem_data);
295             my $pem_data2 = der_to_pem($der_data, "PUBLIC KEY");
296              
297             # others
298             die "mismatch" unless slow_eq($str1, $str2);
299              
300             =head1 DESCRIPTION
301              
302             This module contains a collection of helper functions related to CryptX, but it
303             does not implement cryptography itself.
304              
305             Most of them are also available in other Perl modules. If you already use
306             CryptX, these helpers can reduce extra dependencies.
307              
308             =head1 EXPORT
309              
310             Nothing is exported by default.
311              
312             You can export selected functions:
313              
314             use Crypt::Misc qw(read_rawfile write_rawfile slow_eq);
315              
316             Or all of them at once:
317              
318             use Crypt::Misc ':all';
319              
320             =head1 FUNCTIONS
321              
322             All encoding functions (C, C, etc.) accept a binary
323             string and return an ASCII string. All decoding functions (C,
324             C, etc.) accept an ASCII string and return a binary string, or
325             C if the input is malformed.
326              
327             An empty string is considered valid input and decodes to an empty string.
328             C is considered invalid input and results in C. Non-empty input
329             with no actual payload, such as whitespace-only or padding-only input, is also
330             considered malformed and results in C.
331              
332             The Base64 decoders C and C also accept otherwise
333             valid payload with embedded whitespace. The other decoder families in this
334             module do not; for them, embedded whitespace is treated as malformed input.
335              
336             =head2 read_rawfile
337              
338             I
339              
340             $rawdata = read_rawfile($filename);
341              
342             Reads file C<$filename> into a scalar as binary data, without decoding or
343             transformation.
344              
345             =head2 write_rawfile
346              
347             I
348              
349             write_rawfile($filename, $rawdata);
350              
351             Writes C<$rawdata> to file C<$filename> as binary data.
352              
353             =head2 slow_eq
354              
355             I
356              
357             if (slow_eq($data1, $data2)) { ... }
358              
359             Compares two strings in constant time to reduce timing side channels. Returns
360             C<1> if the strings are equal, C<0> if they differ, or C if either
361             argument is C.
362              
363             =head2 pem_to_der
364              
365             I
366              
367             $der_data = pem_to_der($pem_data);
368             #or
369             $der_data = pem_to_der($pem_data, $password);
370              
371             Converts PEM to DER. Also supports password-protected PEM data.
372             Returns C if C<$pem_data> cannot be parsed (no valid PEM block found)
373             or if the C / C labels do not match. Croaks if the PEM is
374             encrypted but no C<$password> is provided. If an encrypted PEM is supplied
375             with the wrong password, decryption is expected to croak from the underlying
376             cipher/padding layer.
377              
378             =head2 der_to_pem
379              
380             I
381              
382             $pem_data = der_to_pem($der_data, $header_name);
383             #or
384             $pem_data = der_to_pem($der_data, $header_name, $password);
385             #or
386             $pem_data = der_to_pem($der_data, $header_name, $password, $cipher_name);
387              
388             # $header_name e.g. "PUBLIC KEY", "RSA PRIVATE KEY" ...
389             # $cipher_name e.g. "DES-EDE3-CBC", "AES-256-CBC" (DEFAULT) ...
390              
391             Converts DER to PEM. Returns an ASCII PEM string. Also supports
392             password-protected PEM data. Any defined C<$password>, including
393             false-like values like C<''> or C<'0'>, enables PEM encryption.
394              
395             B: do not use ECB-based ciphers (e.g. C) for PEM
396             encryption - ECB encrypts each block independently, leaking plaintext structure.
397             Use the default C or another chaining mode (CBC, CFB, OFB).
398              
399             B: the traditional PEM encryption format uses a single-iteration
400             MD5-based key derivation which is weak against brute-force. For new applications,
401             prefer PKCS#8 encrypted keys (e.g. via L) or
402             an independent encryption layer.
403              
404             =head2 random_v4uuid
405              
406             I
407              
408             my $uuid = random_v4uuid();
409              
410             Returns a cryptographically strong version 4 random UUID:
411             C
412             where C is any hexadecimal digit and C is one of 8, 9, A, B (1000, 1001, 1010, 1011)
413             e.g. C.
414              
415             =head2 is_v4uuid
416              
417             I
418              
419             if (is_v4uuid($uuid)) {
420             ...
421             }
422              
423             Checks whether the given C<$uuid> string matches version 4 UUID format with a
424             relaxed variant policy. The variant nibble may be one of C<0>, C<8>, C<9>,
425             C, or C. Returns C<0> (mismatch) or C<1> (match).
426              
427             =head2 random_v7uuid
428              
429             I
430              
431             my $uuid = random_v7uuid();
432              
433             Returns a cryptographically strong version 7 time-ordered UUID:
434             C
435             where the first 48 bits encode the current Unix time in milliseconds (making UUIDs sortable by
436             generation time), followed by random bits. Ordering is therefore coarse at
437             millisecond granularity only; UUIDs generated within the same millisecond are
438             not guaranteed to be lexicographically monotonic. C is one of 8, 9, A, B
439             (RFC 9562 variant).
440              
441             =head2 is_uuid
442              
443             I
444              
445             if (is_uuid($uuid)) {
446             ...
447             }
448              
449             Checks whether C<$uuid> is a validly formatted UUID (any version) in the standard
450             C form with a relaxed variant policy.
451             The variant nibble may be one of C<0>, C<8>, C<9>, C, or C. Returns
452             C<1> (match) or C<0> (mismatch).
453             For a version-specific check see L.
454              
455             =head2 increment_octets_le
456              
457             I
458              
459             $octets = increment_octets_le($octets);
460              
461             Treats C<$octets> as a little-endian big number and returns the incremented
462             value.
463              
464             =head2 increment_octets_be
465              
466             I
467              
468             $octets = increment_octets_be($octets);
469              
470             Treats C<$octets> as a big-endian big number and returns the incremented value.
471              
472             =head2 encode_b64
473              
474             I
475              
476             $base64string = encode_b64($rawdata);
477              
478             Encodes C<$rawdata> as a Base64 string. No line endings are added.
479              
480             =head2 decode_b64
481              
482             I
483              
484             $rawdata = decode_b64($base64string);
485              
486             Decodes a Base64 string.
487              
488             =head2 encode_b64u
489              
490             I
491              
492             $base64url_string = encode_b64u($rawdata);
493              
494             Encodes C<$rawdata> as a Base64 URL-safe string. No line endings are added.
495              
496             =head2 decode_b64u
497              
498             I
499              
500             $rawdata = decode_b64u($base64url_string);
501              
502             Decodes a Base64 URL-safe string.
503              
504             =head2 encode_b32r
505              
506             I
507              
508             $string = encode_b32r($rawdata);
509              
510             Encode bytes into Base32 (rfc4648 alphabet) string, without "=" padding.
511              
512             =head2 decode_b32r
513              
514             I
515              
516             $rawdata = decode_b32r($string);
517              
518             Decode a Base32 (rfc4648 alphabet) string into bytes.
519              
520             =head2 encode_b32b
521              
522             I
523              
524             $string = encode_b32b($rawdata);
525              
526             Encode bytes into Base32 (base32hex alphabet) string, without "=" padding.
527              
528             =head2 decode_b32b
529              
530             I
531              
532             $rawdata = decode_b32b($string);
533              
534             Decode a Base32 (base32hex alphabet) string into bytes.
535              
536             =head2 encode_b32z
537              
538             I
539              
540             $string = encode_b32z($rawdata);
541              
542             Encode bytes into Base32 (zbase32 alphabet) string.
543              
544             =head2 decode_b32z
545              
546             I
547              
548             $rawdata = decode_b32z($string);
549              
550             Decode a Base32 (zbase32 alphabet) string into bytes.
551              
552             =head2 encode_b32c
553              
554             I
555              
556             $string = encode_b32c($rawdata);
557              
558             Encode bytes into Base32 (crockford alphabet) string.
559              
560             =head2 decode_b32c
561              
562             I
563              
564             $rawdata = decode_b32c($string);
565              
566             Decode a Base32 (crockford alphabet) string into bytes.
567              
568             =head2 encode_b58b
569              
570             I
571              
572             $string = encode_b58b($rawdata);
573              
574             Encode bytes into Base58 (Bitcoin alphabet) string.
575              
576             =head2 decode_b58b
577              
578             I
579              
580             $rawdata = decode_b58b($string);
581              
582             Decode a Base58 (Bitcoin alphabet) string into bytes.
583              
584             =head2 encode_b58f
585              
586             I
587              
588             $string = encode_b58f($rawdata);
589              
590             Encode bytes into Base58 (Flickr alphabet) string.
591              
592             =head2 decode_b58f
593              
594             I
595              
596             $rawdata = decode_b58f($string);
597              
598             Decode a Base58 (Flickr alphabet) string into bytes.
599              
600             =head2 encode_b58r
601              
602             I
603              
604             $string = encode_b58r($rawdata);
605              
606             Encode bytes into Base58 (Ripple alphabet) string.
607              
608             =head2 decode_b58r
609              
610             I
611              
612             $rawdata = decode_b58r($string);
613              
614             Decode a Base58 (Ripple alphabet) string into bytes.
615              
616             =head2 encode_b58t
617              
618             I
619              
620             $string = encode_b58t($rawdata);
621              
622             Encode bytes into Base58 (Tipple alphabet) string.
623              
624             =head2 decode_b58t
625              
626             I
627              
628             $rawdata = decode_b58t($string);
629              
630             Decode a Base58 (Tipple alphabet) string into bytes.
631              
632             =head2 encode_b58s
633              
634             I
635              
636             $string = encode_b58s($rawdata);
637              
638             Encode bytes into Base58 (Stellar alphabet) string.
639              
640             =head2 decode_b58s
641              
642             I
643              
644             $rawdata = decode_b58s($string);
645              
646             Decode a Base58 (Stellar alphabet) string into bytes.
647              
648             =head1 SEE ALSO
649              
650             =over
651              
652             =item * L
653              
654             =back
655              
656             =cut