1Crypt::Cipher(3)      User Contributed Perl Documentation     Crypt::Cipher(3)
2
3
4

NAME

6       Crypt::Cipher - Generic interface to cipher functions
7

SYNOPSIS

9          #### example 1 (encrypting single block)
10          use Crypt::Cipher;
11
12          my $key = '...'; # length has to be valid key size for this cipher
13          my $c = Crypt::Cipher->new('AES', $key);
14          my $blocksize  = $c->blocksize;
15          my $ciphertext = $c->encrypt('plain text block'); #encrypt 1 block
16          my $plaintext  = $c->decrypt($ciphertext);         #decrypt 1 block
17
18          ### example 2 (using CBC mode)
19          use Crypt::Mode::CBC;
20
21          my $key = '...'; # length has to be valid key size for this cipher
22          my $iv = '...';  # 16 bytes
23          my $cbc = Crypt::Mode::CBC->new('AES');
24          my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
25
26          #### example 3 (compatibility with Crypt::CBC)
27          use Crypt::CBC;
28          use Crypt::Cipher;
29
30          my $key = '...'; # length has to be valid key size for this cipher
31          my $iv = '...';  # 16 bytes
32          my $cipher = Crypt::Cipher('AES', $key);
33          my $cbc = Crypt::CBC->new( -cipher=>$cipher, -iv=>$iv );
34          my $ciphertext = $cbc->encrypt("secret data");
35

DESCRIPTION

37       Provides an interface to various symetric cipher algorithms.
38
39       BEWARE: This module implements just elementary
40       "one-block-(en|de)cryption" operation - if you want to encrypt/decrypt
41       generic data you have to use some of the cipher block modes - check for
42       example Crypt::Mode::CBC, Crypt::Mode::CTR or Crypt::CBC (which will be
43       slower).
44

METHODS

46   new
47       Constructor, returns a reference to the cipher object.
48
49        ## basic scenario
50        $d = Crypt::Cipher->new($name, $key);
51        # $name = one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE',
52        #                'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
53        #                'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
54        #                'SEED', 'Skipjack', 'Twofish', 'XTEA'
55        #                simply any <CNAME> for which there exists Crypt::Cipher::<NAME>
56        # $key = binary key (keysize should comply with selected cipher requirements)
57
58        ## some of the ciphers (e.g. MULTI2, RC5, SAFER) allows to set number of rounds
59        $d = Crypt::Cipher->new('MULTI2', $key, $rounds);
60        # $rounds = positive integer (should comply with selected cipher requirements)
61
62   encrypt
63       Encrypts $plaintext and returns the $ciphertext where $plaintext and
64       $ciphertext should be of blocksize bytes.
65
66        $ciphertext = $d->encrypt($plaintext);
67
68   decrypt
69       Decrypts $ciphertext and returns the $plaintext where $plaintext and
70       $ciphertext should be of blocksize bytes.
71
72        $plaintext = $d->encrypt($ciphertext);
73
74   keysize
75       Just an alias for max_keysize (needed for Crypt::CBC compatibility).
76
77   max_keysize
78       Returns the maximal allowed key size (in bytes) for given cipher.
79
80        $d->max_keysize;
81        #or
82        Crypt::Cipher->max_keysize('AES');
83        #or
84        Crypt::Cipher::max_keysize('AES');
85
86   min_keysize
87       Returns the minimal allowed key size (in bytes) for given cipher.
88
89        $d->min_keysize;
90        #or
91        Crypt::Cipher->min_keysize('AES');
92        #or
93        Crypt::Cipher::min_keysize('AES');
94
95   blocksize
96       Returns block size (in bytes) for given cipher.
97
98        $d->blocksize;
99        #or
100        Crypt::Cipher->blocksize('AES');
101        #or
102        Crypt::Cipher::blocksize('AES');
103
104   default_rounds
105       Returns default number of rounds for given cipher. NOTE: only some
106       cipher (e.g. MULTI2, RC5, SAFER) allows to set number of rounds via
107       new().
108
109        $d->default_rounds;
110        #or
111        Crypt::Cipher->default_rounds('AES');
112        #or
113        Crypt::Cipher::default_rounds('AES');
114

SEE ALSO

116       ·   CryptX
117
118       ·   Check subclasses like Crypt::Cipher::AES, Crypt::Cipher::Blowfish,
119           ...
120
121
122
123perl v5.32.1                      2021-03-30                  Crypt::Cipher(3)
Impressum