2
votes

I'm toying around with openssl to learn more about symmetric encryption. I read that one reason ECB (Electronic Codebook) mode is not as secure as CBC (Cipher Block Chaining) is due to the fact that in ECB mode, the cipher (in this case, aes-128), encrypts in 128 bits at a time, which could result in the same sequence appearing. For example, if the word "security" appears multiple times in the file, and they happen to be aligned in a 128-bit sequence, repeated sequences should appear. I'm trying to see this effect in a practical setting, specifically, with openssl.

The command I typed was:

openssl aes-128-ecb -a -in plain.txt -out cipher.txt

plain.txt contained: 0123456789abcdef0123456789abcdef

The encryption password I used was "password" (without the double quotes).

cipher.txt contained: U2FsdGVkX18qCQ5SjLaVsLS8als/h5eJl69ATS3pD94x5kwkpmfNWauW/lUOZdeC 5a38fSS7mTUc7hT7XiXdIw==

If I am understanding everything correctly, each character in plain.txt should represent one byte. 16 characters = 128 bits. As you can see, I'm trying to align the sequences in 128-bit blocks to see the repeated sequences.

What's wrong with the logic above?

1

1 Answers

8
votes

Your command line uses base64, salt, and padding, all of which mess things up. Try:

openssl aes-128-ecb -in plain.text -out cipher.txt -nosalt -nopad

You'll find that cipher.txt contains 32 bytes:

 83 d2 41 fb ca 6e 8a e3 3b 6e 55 ae 2c ac 62 af
 83 d2 41 fb ca 6e 8a e3 3b 6e 55 ae 2c ac 62 af