.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Crypt::Cipher 3" .TH Crypt::Cipher 3 2026-08-10 "perl v5.42.2" "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::Cipher \- Generic interface to cipher functions .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& #### example 1 (encrypting single block) \& use Crypt::Cipher; \& \& my $key = \*(Aq1234567890abcdef\*(Aq; # 16 bytes, valid for AES\-128 \& my $plaintext_block = \*(Aq1234567890123456\*(Aq; # one AES block (16 bytes) \& my $c = Crypt::Cipher\->new(\*(AqAES\*(Aq, $key); \& my $blocksize = $c\->blocksize; \& my $ciphertext = $c\->encrypt($plaintext_block); # encrypt 1 block \& my $plaintext = $c\->decrypt($ciphertext); #decrypt 1 block \& \& ### example 2 (using CBC mode) \& use Crypt::Mode::CBC; \& \& my $cbc_key = \*(Aq1234567890abcdef\*(Aq; # 16 bytes, valid for AES\-128 \& my $iv = \*(Aqfedcba0987654321\*(Aq; # 16 bytes \& my $cbc = Crypt::Mode::CBC\->new(\*(AqAES\*(Aq); \& my $cbc_ciphertext = $cbc\->encrypt("secret data", $cbc_key, $iv); \& \& #### example 3 (compatibility with Crypt::CBC) \& use Crypt::CBC; \& use Crypt::Cipher; \& \& my $compat_key = \*(Aq1234567890abcdef\*(Aq; # 16 bytes, valid for AES\-128 \& my $compat_iv = \*(Aqfedcba0987654321\*(Aq; # 16 bytes \& my $cipher = Crypt::Cipher\->new(\*(AqAES\*(Aq, $compat_key); \& my $compat_cbc = Crypt::CBC\->new( \-cipher=>$cipher, \-iv=>$compat_iv ); \& my $compat_ciphertext = $compat_cbc\->encrypt("secret data"); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Provides an interface to various symmetric cipher algorithms. .PP \&\fBNote:\fR This module only implements single\-block encryption and decryption. For general data, use a block mode such as Crypt::Mode::CBC, Crypt::Mode::CTR, or Crypt::CBC (which is slower). .SH METHODS .IX Header "METHODS" Unless noted otherwise, assume \f(CW$c\fR is an existing cipher object created via \&\f(CW\*(C`new\*(C'\fR, for example: .PP .Vb 1 \& my $c = Crypt::Cipher\->new(\*(AqAES\*(Aq, \*(Aq1234567890abcdef\*(Aq); .Ve .SS new .IX Subsection "new" Constructor. Returns a reference to the cipher object. .PP .Vb 8 \& ## basic scenario \& my $c = Crypt::Cipher\->new($name, $key); \& # $name = one of \*(AqAES\*(Aq, \*(AqAnubis\*(Aq, \*(AqBlowfish\*(Aq, \*(AqCAST5\*(Aq, \*(AqCamellia\*(Aq, \*(AqDES\*(Aq, \*(AqDES_EDE\*(Aq, \& # \*(AqKASUMI\*(Aq, \*(AqKhazad\*(Aq, \*(AqMULTI2\*(Aq, \*(AqNoekeon\*(Aq, \*(AqRC2\*(Aq, \*(AqRC5\*(Aq, \*(AqRC6\*(Aq, \& # \*(AqSAFERP\*(Aq, \*(AqSAFER_K128\*(Aq, \*(AqSAFER_K64\*(Aq, \*(AqSAFER_SK128\*(Aq, \*(AqSAFER_SK64\*(Aq, \& # \*(AqSEED\*(Aq, \*(AqSM4\*(Aq, \*(AqSkipjack\*(Aq, \*(AqTwofish\*(Aq, \*(AqXTEA\*(Aq, \*(AqIDEA\*(Aq, \*(AqSerpent\*(Aq \& # or any for which there is a Crypt::Cipher:: module \& # $key = binary key (keysize should comply with selected cipher requirements) \& \& ## some of the ciphers (e.g. MULTI2, RC5, SAFER) allow one to set number of rounds \& my $c = Crypt::Cipher\->new(\*(AqMULTI2\*(Aq, $key, $rounds); \& # $rounds = positive integer (should comply with selected cipher requirements) .Ve .SS encrypt .IX Subsection "encrypt" Encrypts \f(CW$plaintext\fR and returns \f(CW$ciphertext\fR. An empty string is accepted and returned unchanged; otherwise \f(CW$plaintext\fR must be exactly \&\fBblocksize\fR bytes long. .PP .Vb 1 \& my $ciphertext = $c\->encrypt($plaintext); .Ve .SS decrypt .IX Subsection "decrypt" Decrypts \f(CW$ciphertext\fR and returns \f(CW$plaintext\fR. An empty string is accepted and returned unchanged; otherwise \f(CW$ciphertext\fR must be exactly \&\fBblocksize\fR bytes long. .PP .Vb 1 \& my $plaintext = $c\->decrypt($ciphertext); .Ve .SS keysize .IX Subsection "keysize" Just an alias for \fBmax_keysize\fR (needed for Crypt::CBC compatibility). .SS max_keysize .IX Subsection "max_keysize" Returns the maximum allowed key size in bytes for the given cipher. .PP .Vb 5 \& $c\->max_keysize; \& #or \& Crypt::Cipher\->max_keysize(\*(AqAES\*(Aq); \& #or \& Crypt::Cipher::max_keysize(\*(AqAES\*(Aq); .Ve .SS min_keysize .IX Subsection "min_keysize" Returns the minimum allowed key size in bytes for the given cipher. .PP .Vb 5 \& $c\->min_keysize; \& #or \& Crypt::Cipher\->min_keysize(\*(AqAES\*(Aq); \& #or \& Crypt::Cipher::min_keysize(\*(AqAES\*(Aq); .Ve .SS blocksize .IX Subsection "blocksize" Returns the block size in bytes for the given cipher. .PP .Vb 5 \& $c\->blocksize; \& #or \& Crypt::Cipher\->blocksize(\*(AqAES\*(Aq); \& #or \& Crypt::Cipher::blocksize(\*(AqAES\*(Aq); .Ve .SS default_rounds .IX Subsection "default_rounds" Returns the default number of rounds for the given cipher. Only some ciphers, such as MULTI2, RC5, and SAFER, let you set the number of rounds via \f(CWnew()\fR. .PP .Vb 5 \& $c\->default_rounds; \& #or \& Crypt::Cipher\->default_rounds(\*(AqAES\*(Aq); \& #or \& Crypt::Cipher::default_rounds(\*(AqAES\*(Aq); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .IP \(bu 4 CryptX .IP \(bu 4 See subclasses such as Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...