.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" 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::Cipher 3pm" .TH Crypt::Cipher 3pm "2018-12-01" "perl v5.28.1" "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 = \*(Aq...\*(Aq; # length has to be valid key size for this cipher \& my $c = Crypt::Cipher\->new(\*(AqAES\*(Aq, $key); \& my $blocksize = $c\->blocksize; \& my $ciphertext = $c\->encrypt(\*(Aqplain text block\*(Aq); #encrypt 1 block \& my $plaintext = $c\->decrypt($ciphertext); #decrypt 1 block \& \& ### example 2 (using CBC mode) \& use Crypt::Mode::CBC; \& \& my $key = \*(Aq...\*(Aq; # length has to be valid key size for this cipher \& my $iv = \*(Aq...\*(Aq; # 16 bytes \& my $cbc = Crypt::Mode::CBC\->new(\*(AqAES\*(Aq); \& my $ciphertext = $cbc\->encrypt("secret data", $key, $iv); \& \& #### example 3 (compatibility with Crypt::CBC) \& use Crypt::CBC; \& use Crypt::Cipher; \& \& my $key = \*(Aq...\*(Aq; # length has to be valid key size for this cipher \& my $iv = \*(Aq...\*(Aq; # 16 bytes \& my $cipher = Crypt::Cipher(\*(AqAES\*(Aq, $key); \& my $cbc = Crypt::CBC\->new( \-cipher=>$cipher, \-iv=>$iv ); \& my $ciphertext = $cbc\->encrypt("secret data"); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Provides an interface to various symmetric cipher algorithms. .PP \&\fB\s-1BEWARE:\s0\fR This module implements just elementary \*(L"one\-block\-(en|de)cryption\*(R" operation \- if you want to encrypt/decrypt generic data you have to use some of the cipher block modes \- check for example Crypt::Mode::CBC, Crypt::Mode::CTR or Crypt::CBC (which will be slower). .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Constructor, returns a reference to the cipher object. .PP .Vb 8 \& ## basic scenario \& $d = 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, \*(AqSkipjack\*(Aq, \*(AqTwofish\*(Aq, \*(AqXTEA\*(Aq, \*(AqIDEA\*(Aq, \*(AqSerpent\*(Aq \& # simply any for which there exists Crypt::Cipher:: \& # $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 \& $d = 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 the \f(CW$ciphertext\fR where \f(CW$plaintext\fR and \f(CW$ciphertext\fR should be of \fBblocksize\fR bytes. .PP .Vb 1 \& $ciphertext = $d\->encrypt($plaintext); .Ve .SS "decrypt" .IX Subsection "decrypt" Decrypts \f(CW$ciphertext\fR and returns the \f(CW$plaintext\fR where \f(CW$plaintext\fR and \f(CW$ciphertext\fR should be of \fBblocksize\fR bytes. .PP .Vb 1 \& $plaintext = $d\->encrypt($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 maximal allowed key size (in bytes) for given cipher. .PP .Vb 5 \& $d\->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 minimal allowed key size (in bytes) for given cipher. .PP .Vb 5 \& $d\->min_keysize; \& #or \& Crypt::Cipher\->min_keysize(\*(AqAES\*(Aq); \& #or \& Crypt::Cipher::min_keysize(\*(AqAES\*(Aq); .Ve .SS "blocksize" .IX Subsection "blocksize" Returns block size (in bytes) for given cipher. .PP .Vb 5 \& $d\->blocksize; \& #or \& Crypt::Cipher\->blocksize(\*(AqAES\*(Aq); \& #or \& Crypt::Cipher::blocksize(\*(AqAES\*(Aq); .Ve .SS "default_rounds" .IX Subsection "default_rounds" Returns default number of rounds for given cipher. \s-1NOTE:\s0 only some ciphers (e.g. \s-1MULTI2, RC5, SAFER\s0) allow one to set number of rounds via \fBnew()\fR. .PP .Vb 5 \& $d\->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 Check subclasses like Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...