跳到主要内容
uencoder

Stream Cipher

流密码逐字节或逐位加密,用密钥流与明文异或得密文,无需填充,适合实时与流式数据。

用途

提供无需分组对齐的高效加密,适合网络流与连续数据。

机制

加密 C_i = P_i ⊕ S_i,其中 S 为密钥流(由密钥与 nonce/计数器经 PRG 生成)。解密相同(异或自逆)。安全性依赖密钥流的伪随机性与 nonce 唯一性。常见构造:基于 ARX(ChaCha)、基于 LFSR、AES-CTR 模式。

用例

  • TLS 1.3 流密码加密(ChaCha20-Poly1305)
  • 实时音视频加密
  • WireGuard VPN 隧道
  • 嵌入式低资源加密

示例

  • 输入
    key + nonce → keystream
    输出
    C = P ⊕ S

    The nonce must never repeat

常见错误

Encrypting two messages with the same key+nonce (a two-time pad)
Use a unique nonce or counter per message

相关词条

相关工具

参考链接