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('AES');
35        #or
36        my $m = Crypt::Mode::CBC->new('AES', $padding);
37        #or
38        my $m = Crypt::Mode::CBC->new('AES', $padding, $cipher_rounds);
39
40        # $padding .... 0 no padding (plaintext size has to be myltiple of block length)
41        #               1 PKCS5 padding, Crypt::CBC's "standard" - DEFAULT
42        #               2 Crypt::CBC's "oneandzeroes"
43        # $cipher_rounds ... optional num of rounds for given cipher
44
45   encrypt
46          my $ciphertext = $m->encrypt($plaintext, $key, $iv);
47
48   decrypt
49          my $plaintext = $m->decrypt($ciphertext, $key, $iv);
50
51   start_encrypt
52          $m->start_encrypt($key, $iv);
53
54   start_decrypt
55          $m->start_decrypt($key, $iv);
56
57   add
58          # in encrypt mode
59          my $plaintext = $m->add($ciphertext);
60
61          # in decrypt mode
62          my $ciphertext = $m->add($plaintext);
63
64   finish
65          #encrypt more chunks
66          $m->start_encrypt($key, $iv);
67          my $ciphertext = '';
68          $ciphertext .= $m->add('some data');
69          $ciphertext .= $m->add('more data');
70          $ciphertext .= $m->finish;
71
72          #decrypt more chunks
73          $m->start_decrypt($key, $iv);
74          my $plaintext = '';
75          $plaintext .= $m->add($some_ciphertext);
76          $plaintext .= $m->add($more_ciphertext);
77          $plaintext .= $m->finish;
78

SEE ALSO

80       ·   CryptX, Crypt::Cipher
81
82       ·   Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...
83
84       ·   <https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_chaining_.28CBC.29>
85
86
87
88perl v5.32.1                      2021-03-30               Crypt::Mode::CBC(3)
Impressum