跳到主要内容
uencoder

CBC (Cipher Block Chaining)

CBC 模式将前块密文与当前明文异或后再加密,使相同明文块产生不同密文,需随机 IV,但不提供完整性认证。

用途

消除 ECB 的相同明文块模式,提供机密性,但需额外 MAC 保证完整性。

机制

加密 C_i = E_K(P_i ⊕ C_{i-1}),C_0 = IV。解密 P_i = D_K(C_i) ⊕ C_{i-1}。IV 必须不可预测(随机)。错误传播仅影响当前与下一块。无认证,需配合 HMAC(Encrypt-then-MAC)。

用例

  • 文件加密(如 OpenSSL 默认)
  • 数据库字段加密
  • IPsec ESP(历史)
  • 磁盘加密(部分)

示例

  • 输入
    IV + P1 P2 P3
    输出
    C1 C2 C3

    Each block depends on the previous one

常见错误

A predictable IV enables chosen-plaintext attacks
Use a random IV and transmit it with the ciphertext
Lack of authentication invites padding attacks (e.g., POODLE)
Use an AEAD mode or Encrypt-then-MAC

相关词条

相关工具

参考链接