Streams and Blocks

Symmetric ciphers come in two varieties. Block ciphers encrypt and decrypt fixed-size blocks of data, usually 64 bits long. Stream ciphers operate on a stream of bits or bytes. The distinction is blurry, however. A block cipher can be made to work like a stream cipher, using the appropriate mode (CFB). I’ll talk about this soon. Asymmetric ciphers are block ciphers.

Before computers, encryption was accomplished using stream ciphers, which are ciphers that operate on one character of a message at a time. The use of computers in cryptography has led to the creation of block ciphers, in which a message is broken into blocks. The cipher encrypts or decrypts one block at a time. When would you choose a block or stream cipher? It depends on the application. In a cryptographically enabled Telnet application, for example, using a block cipher would be awkward. In telnet, the server should receive each character that the client types, as it is typed. If you were encrypting the data between the client and server with a block cipher, you’d have to wait until the client typed enough characters to fill a block. In this case, a stream cipher is better suited to the task.

Be that as it may, block cipher algorithms are much more prevalent than stream cipher algorithms. If you need a stream cipher (as you will in Chapter 10), then use a block cipher in CFB mode.

Get Java Cryptography now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.