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

NAME

6       Crypt::Mode::CBC - Block cipher mode CBC [Cipher-block chaining]
7

SYNOPSIS

9          use Crypt::Mode::CBC;
10          my $m = Crypt::Mode::CBC->new('AES');
11
12          #(en|de)crypt at once
13          my $ciphertext = $m->encrypt($plaintext, $key, $iv);
14          my $plaintext = $m->decrypt($ciphertext, $key, $iv);
15
16          #encrypt more chunks
17          $m->start_encrypt($key, $iv);
18          my $ciphertext = $m->add('some data');
19          $ciphertext .= $m->add('more data');
20          $ciphertext .= $m->finish;
21
22          #decrypt more chunks
23          $m->start_decrypt($key, $iv);
24          my $plaintext = $m->add($some_ciphertext);
25          $plaintext .= $m->add($more_ciphertext);
26          $plaintext .= $m->finish;
27

DESCRIPTION

29       This module implements CBC cipher mode. NOTE: it works only with
30       ciphers from CryptX (Crypt::Cipher::NNNN).
31

METHODS

33   new
34        my $m = Crypt::Mode::CBC->new($name);
35        #or
36        my $m = Crypt::Mode::CBC->new($name, $padding);
37        #or
38        my $m = Crypt::Mode::CBC->new($name, $padding, $cipher_rounds);
39
40        # $name ....... one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE',
41        #               'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
42        #               'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
43        #               'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'
44        #               simply any <NAME> for which there exists Crypt::Cipher::<NAME>
45        # $padding .... 0 no padding (plaintext size has to be multiple of block length)
46        #               1 PKCS5 padding, Crypt::CBC's "standard" - DEFAULT
47        #               2 Crypt::CBC's "oneandzeroes"
48        #               3 ANSI X.923 padding
49        #               4 zero padding
50        #               5 zero padding (+a block of zeros if the output length is divisible by the blocksize)
51        # $cipher_rounds ... optional num of rounds for given cipher
52
53   encrypt
54          my $ciphertext = $m->encrypt($plaintext, $key, $iv);
55
56   decrypt
57          my $plaintext = $m->decrypt($ciphertext, $key, $iv);
58
59   start_encrypt
60          $m->start_encrypt($key, $iv);
61
62   start_decrypt
63          $m->start_decrypt($key, $iv);
64
65   add
66          # in encrypt mode
67          my $plaintext = $m->add($ciphertext);
68
69          # in decrypt mode
70          my $ciphertext = $m->add($plaintext);
71
72   finish
73          #encrypt more chunks
74          $m->start_encrypt($key, $iv);
75          my $ciphertext = '';
76          $ciphertext .= $m->add('some data');
77          $ciphertext .= $m->add('more data');
78          $ciphertext .= $m->finish;
79
80          #decrypt more chunks
81          $m->start_decrypt($key, $iv);
82          my $plaintext = '';
83          $plaintext .= $m->add($some_ciphertext);
84          $plaintext .= $m->add($more_ciphertext);
85          $plaintext .= $m->finish;
86

SEE ALSO

88       •   CryptX, Crypt::Cipher
89
90       •   Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...
91
92       •   <https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_chaining_.28CBC.29>
93
94
95
96perl v5.38.0                      2023-10-04               Crypt::Mode::CBC(3)
Impressum