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

NAME

6       Crypt::Mode::ECB - Block cipher mode ECB [Electronic codebook]
7

SYNOPSIS

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

DESCRIPTION

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

METHODS

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

SEE ALSO

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