.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Crypt::Misc 3pm" .TH Crypt::Misc 3pm "2022-10-19" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Crypt::Misc \- miscellaneous functions related to (or used by) CryptX .SH "SYNOPSIS" .IX Header "SYNOPSIS" This module contains a collection of mostly unsorted functions loosely-related to CryptX distribution but not implementing cryptography. .PP Most of them are also available in other perl modules but once you utilize CryptX you might avoid dependencies on other modules by using functions from Crypt::Misc. .SH "DESCRIPTION" .IX Header "DESCRIPTION" .Vb 1 \& use Crypt::Misc \*(Aq:all\*(Aq; \& \& # Base64 and Base64/URL\-safe functions \& $base64 = encode_b64($rawbytes); \& $rawbytes = decode_b64($base64); \& $base64url = encode_b64u($encode_b64u); \& $rawbytes = decode_b64u($base64url); \& \& # read/write file \& $rawdata = read_rawfile($filename); \& write_rawfile($filename, $rawdata); \& \& # convert PEM/DER \& $der_data = pem_to_der($pem_data); \& $pem_data = der_to_pem($der_data); \& \& # others \& die "mismatch" unless slow_eq($str1, $str2); .Ve .SH "FUNCTIONS" .IX Header "FUNCTIONS" By default, Crypt::Misc doesn't import any function. You can import individual functions like this: .PP .Vb 1 \& use Crypt::Misc qw(read_rawfile); .Ve .PP Or import all available functions: .PP .Vb 1 \& use Crypt::Misc \*(Aq:all\*(Aq; .Ve .SS "read_rawfile" .IX Subsection "read_rawfile" \&\fISince: 0.029\fR .PP .Vb 1 \& $rawdata = read_rawfile($filename); .Ve .PP Read file \f(CW$filename\fR into a scalar as a binary data (without decoding/transformation). .SS "write_rawfile" .IX Subsection "write_rawfile" \&\fISince: 0.029\fR .PP .Vb 1 \& write_rawfile($filename, $rawdata); .Ve .PP Write \f(CW$rawdata\fR to file \f(CW$filename\fR as binary data. .SS "slow_eq" .IX Subsection "slow_eq" \&\fISince: 0.029\fR .PP .Vb 1 \& if (slow_eq($data1, $data2)) { ... } .Ve .PP Constant time compare (to avoid timing side-channel). .SS "pem_to_der" .IX Subsection "pem_to_der" \&\fISince: 0.029\fR .PP .Vb 3 \& $der_data = pem_to_der($pem_data); \& #or \& $der_data = pem_to_der($pem_data, $password); .Ve .PP Convert \s-1PEM\s0 to \s-1DER\s0 representation. Supports also password protected \s-1PEM\s0 data. .SS "der_to_pem" .IX Subsection "der_to_pem" \&\fISince: 0.029\fR .PP .Vb 5 \& $pem_data = der_to_pem($der_data, $header_name); \& #or \& $pem_data = der_to_pem($der_data, $header_name, $password); \& #or \& $pem_data = der_to_pem($der_data, $header_name, $passord, $cipher_name); \& \& # $header_name e.g. "PUBLIC KEY", "RSA PRIVATE KEY" ... \& # $cipher_name e.g. "DES\-EDE3\-CBC", "AES\-256\-CBC" (DEFAULT) ... .Ve .PP Convert \s-1DER\s0 to \s-1PEM\s0 representation. Supports also password protected \s-1PEM\s0 data. .SS "random_v4uuid" .IX Subsection "random_v4uuid" \&\fISince: 0.031\fR .PP .Vb 1 \& my $uuid = random_v4uuid(); .Ve .PP Returns cryptographically strong Version 4 random \s-1UUID:\s0 \f(CW\*(C`xxxxxxxx\-xxxx\-4xxx\-Yxxx\-xxxxxxxxxxxx\*(C'\fR where \f(CW\*(C`x\*(C'\fR is any hexadecimal digit and \f(CW\*(C`Y\*(C'\fR is one of 8, 9, A, B (1000, 1001, 1010, 1011) e.g. \f(CW\*(C`f47ac10b\-58cc\-4372\-a567\-0e02b2c3d479\*(C'\fR. .SS "is_v4uuid" .IX Subsection "is_v4uuid" \&\fISince: 0.031\fR .PP .Vb 3 \& if (is_v4uuid($uuid)) { \& ... \& } .Ve .PP Checks the given \f(CW$uuid\fR string whether it matches V4 \s-1UUID\s0 format and returns \f(CW0\fR (mismatch) or \f(CW1\fR (match). .SS "increment_octets_le" .IX Subsection "increment_octets_le" \&\fISince: 0.048\fR .PP .Vb 1 \& $octects = increment_octets_le($octets); .Ve .PP Take input \f(CW$octets\fR as a little-endian big number and return an increment. .SS "increment_octets_be" .IX Subsection "increment_octets_be" \&\fISince: 0.048\fR .PP .Vb 1 \& $octects = increment_octets_be($octets); .Ve .PP Take input \f(CW$octets\fR as a big-endian big number and return an increment. .SS "encode_b64" .IX Subsection "encode_b64" \&\fISince: 0.029\fR .PP .Vb 1 \& $base64string = encode_b64($rawdata); .Ve .PP Encode \f(CW$rawbytes\fR into Base64 string, no line-endings in the output string. .SS "decode_b64" .IX Subsection "decode_b64" \&\fISince: 0.029\fR .PP .Vb 1 \& $rawdata = decode_b64($base64string); .Ve .PP Decode a Base64 string. .SS "encode_b64u" .IX Subsection "encode_b64u" \&\fISince: 0.029\fR .PP .Vb 1 \& $base64url_string = encode_b64($rawdata); .Ve .PP Encode \f(CW$rawbytes\fR into Base64/URL\-Safe string, no line-endings in the output string. .SS "decode_b64u" .IX Subsection "decode_b64u" \&\fISince: 0.029\fR .PP .Vb 1 \& $rawdata = decode_b64($base64url_string); .Ve .PP Decode a Base64/URL\-Safe string. .SS "encode_b32r" .IX Subsection "encode_b32r" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b32r($rawdata); .Ve .PP Encode bytes into Base32 (rfc4648 alphabet) string, without \*(L"=\*(R" padding. .SS "decode_b32r" .IX Subsection "decode_b32r" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b32r($string); .Ve .PP Decode a Base32 (rfc4648 alphabet) string into bytes. .SS "encode_b32b" .IX Subsection "encode_b32b" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b32b($rawdata); .Ve .PP Encode bytes into Base32 (base32hex alphabet) string, without \*(L"=\*(R" padding. .SS "decode_b32b" .IX Subsection "decode_b32b" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b32b($string); .Ve .PP Decode a Base32 (base32hex alphabet) string into bytes. .SS "encode_b32z" .IX Subsection "encode_b32z" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b32z($rawdata); .Ve .PP Encode bytes into Base32 (zbase32 alphabet) string. .SS "decode_b32z" .IX Subsection "decode_b32z" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b32z($string); .Ve .PP Decode a Base32 (zbase32 alphabet) string into bytes. .SS "encode_b32c" .IX Subsection "encode_b32c" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b32c($rawdata); .Ve .PP Encode bytes into Base32 (crockford alphabet) string. .SS "decode_b32c" .IX Subsection "decode_b32c" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b32c($string); .Ve .PP Decode a Base32 (crockford alphabet) string into bytes. .SS "encode_b58b" .IX Subsection "encode_b58b" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b58b($rawdata); .Ve .PP Encode bytes into Base58 (Bitcoin alphabet) string. .SS "decode_b58b" .IX Subsection "decode_b58b" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b58b($string); .Ve .PP Decode a Base58 (Bitcoin alphabet) string into bytes. .SS "encode_b58f" .IX Subsection "encode_b58f" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b58f($rawdata); .Ve .PP Encode bytes into Base58 (Flickr alphabet) string. .SS "decode_b58f" .IX Subsection "decode_b58f" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b58f($string); .Ve .PP Decode a Base58 (Flickr alphabet) string into bytes. .SS "encode_b58r" .IX Subsection "encode_b58r" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b58r($rawdata); .Ve .PP Encode bytes into Base58 (Ripple alphabet) string. .SS "decode_b58r" .IX Subsection "decode_b58r" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b58r($string); .Ve .PP Decode a Base58 (Ripple alphabet) string into bytes. .SS "encode_b58t" .IX Subsection "encode_b58t" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b58t($rawdata); .Ve .PP Encode bytes into Base58 (Tipple alphabet) string. .SS "decode_b58t" .IX Subsection "decode_b58t" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b58t($string); .Ve .PP Decode a Base58 (Tipple alphabet) string into bytes. .SS "encode_b58s" .IX Subsection "encode_b58s" \&\fISince: 0.049\fR .PP .Vb 1 \& $string = encode_b58s($rawdata); .Ve .PP Encode bytes into Base58 (Stellar alphabet) string. .SS "decode_b58s" .IX Subsection "decode_b58s" \&\fISince: 0.049\fR .PP .Vb 1 \& $rawdata = decode_b58s($string); .Ve .PP Decode a Base58 (Stellar alphabet) string into bytes. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 CryptX