1Crypt::Mode::ECB(3) User Contributed Perl Documentation Crypt::Mode::ECB(3)
2
3
4
6 Crypt::Mode::ECB - Block cipher mode ECB [Electronic codebook]
7
9 use Crypt::Mode::ECB;
10 my $m = Crypt::Mode::ECB->new('AES');
11
12 #(en|de)crypt at once
13 my $ciphertext = $m->encrypt($plaintext, $key);
14 my $plaintext = $m->decrypt($ciphertext, $key);
15
16 #encrypt more chunks
17 $m->start_encrypt($key);
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);
24 my $plaintext = $m->add($some_ciphertext);
25 $plaintext .= $m->add($more_ciphertext);
26 $plaintext .= $m->finish;
27
29 This module implements ECB cipher mode. NOTE: it works only with
30 ciphers from CryptX (Crypt::Cipher::NNNN). BEWARE: ECB is inherently
31 insecure, if you are not sure go for Crypt::Mode::CBC!
32
34 new
35 my $m = Crypt::Mode::ECB->new('AES');
36 #or
37 my $m = Crypt::Mode::ECB->new('AES', $padding);
38 #or
39 my $m = Crypt::Mode::ECB->new('AES', $padding, $cipher_rounds);
40
41 # $padding .... 0 no padding (plaintext size has to be myltiple of block length)
42 # 1 PKCS5 padding, Crypt::CBC's "standard" - DEFAULT
43 # 2 Crypt::CBC's "oneandzeroes"
44 # $cipher_rounds ... optional num of rounds for given cipher
45
46 encrypt
47 my $ciphertext = $m->encrypt($plaintext, $key);
48
49 decrypt
50 my $plaintext = $m->decrypt($ciphertext, $key);
51
52 start_encrypt
53 $m->start_encrypt($key);
54
55 start_decrypt
56 $m->start_decrypt($key);
57
58 add
59 # in encrypt mode
60 my $plaintext = $m->add($ciphertext);
61
62 # in decrypt mode
63 my $ciphertext = $m->add($plaintext);
64
65 finish
66 #encrypt more chunks
67 $m->start_encrypt($key);
68 my $ciphertext = '';
69 $ciphertext .= $m->add('some data');
70 $ciphertext .= $m->add('more data');
71 $ciphertext .= $m->finish;
72
73 #decrypt more chunks
74 $m->start_decrypt($key);
75 my $plaintext = '';
76 $plaintext .= $m->add($some_ciphertext);
77 $plaintext .= $m->add($more_ciphertext);
78 $plaintext .= $m->finish;
79
81 · CryptX, Crypt::Cipher
82
83 · Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...
84
85 · <https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_.28ECB.29>
86
87
88
89perl v5.32.1 2021-03-30 Crypt::Mode::ECB(3)