Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

What Is a Block Cipher? AES and Its Modes Explained

Learn why AES needs a mode of operation, how ECB, CBC, CFB, OFB, CTR, and GCM differ, and what to choose for new applications.

Table of Contents

A block cipher transforms a fixed-size block of data using a secret key. AES is a block cipher with a 128-bit block size and 128-, 192-, or 256-bit keys. A mode of operation defines how to use the cipher on a message, including how it handles multiple blocks and whether it checks for tampering.

What is Block Cipher? Block Cipher Operation Modes Picture 1
A block cipher processes fixed-size blocks. The mode defines how to protect a complete message.

What the common modes do

ModeHow it worksWhat to watch for
ECBEncrypts each block independently.Equal plaintext blocks under the same key produce equal ciphertext blocks. This can expose patterns.
CBCCombines each plaintext block with the previous ciphertext block. The first uses an initialization vector (IV).Requires correct IV and padding handling. It provides no authentication by itself.
CFBFeeds ciphertext back into the process to encrypt subsequent data.Can work in segments shorter than a block. It provides no authentication by itself.
OFBFeeds back the cipher’s output to produce a keystream.Repeating the IV with the same key can repeat the keystream.
CTREncrypts successive counter values to produce a keystream.Supports parallel processing. Counter blocks must never repeat under the same key.
GCMCombines counter-mode encryption with an authentication tag.Requires unique nonces per key and verification of the tag before using the plaintext.
What is Block Cipher? Block Cipher Operation Modes Picture 2
CBC uses the previous ciphertext block when encrypting the next plaintext block.

NIST documents the confidentiality modes and authenticated encryption with GCM separately. A standalone message authentication code can check integrity but does not encrypt the message.

Choose an established format and library

For a new app, use a maintained library’s authenticated encryption API or a protocol that handles it for you. An API such as AES-GCM can also authenticate unencrypted metadata, such as a message version, as associated data. Follow the library’s guidance for nonce generation, key storage, and errors. If verification fails, reject the returned data.

If you need to protect a folder rather than implement a protocol, see an example of file encryption with gocryptfs. For websites, see how to check an existing TLS configuration.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.