7. Serializations (序列化)
JWE 使用 JWE Compact Serialization 或 JWE JSON Serialization. 应用需要明确支持哪种 serialization, 是否支持单 recipient 或多 recipient.
7.1 JWE Compact Serialization (紧凑序列化)
Compact Serialization 是紧凑 URL-safe 字符串, 由五个 base64url-encoded 部分组成:
BASE64URL(UTF8(JWE Protected Header)) || '.' ||
BASE64URL(JWE Encrypted Key) || '.' ||
BASE64URL(JWE Initialization Vector) || '.' ||
BASE64URL(JWE Ciphertext) || '.' ||
BASE64URL(JWE Authentication Tag)
该形式只支持一个 recipient, 也没有语法表示 JWE Shared Unprotected Header, JWE Per-Recipient Unprotected Header 或 JWE AAD.
7.2 JWE JSON Serialization (JSON 序列化)
JWE JSON Serialization 使用 JSON object 表示 encrypted content, 不追求紧凑性, 也不是 URL-safe. 它有 general syntax 和 flattened syntax.
General syntax 使用顶层 protected, unprotected, recipients, aad, iv, ciphertext 和 tag 等 member. recipients 是 recipient object 数组, 每个元素可含 header 和 encrypted_key. JOSE Header 是 protected, shared unprotected 和 per-recipient unprotected header 的并集, 三处 Header Parameter name MUST 互不相交.
Flattened syntax 面向单 recipient, 去掉 recipients 数组, 把 header 和 encrypted_key 放在顶层. 除语法差异外, 处理方式与 general syntax 相同.