Skip to content

加密信封

Open POST 请求和平台加密响应都使用同一种信封结构:

json
{
  "encrypted_key": "base64(RSA-OAEP(public_key, content_key))",
  "biz_content": "base64(aes_gcm_nonce || aes_gcm_ciphertext || aes_gcm_tag)"
}

算法

项目算法
内容密钥每次消息随机生成 32 字节 content_key
非对称加密RSA-OAEP 加密 content_key
业务内容加密AES-256-GCM 加密业务 JSON。
编码encrypted_keybiz_content 均使用 Base64。

请求加密

商户调用 Open POST 接口时:

  1. 生成业务 JSON。
  2. 随机生成 32 字节 content_key
  3. 使用平台公钥 platform_public_key RSA-OAEP 加密 content_key,得到 encrypted_key
  4. 使用 content_key AES-256-GCM 加密业务 JSON。
  5. nonce || ciphertext || tag 拼接后 Base64,得到 biz_content
  6. 对最终信封 JSON 计算签名并发送。

响应解密

Open POST 成功响应的 data 是平台返回给商户的加密信封。商户处理顺序:

  1. 校验响应 X-Signature
  2. 使用商户私钥 merchant_private_key 解密 data.encrypted_key 得到 content_key
  3. 使用 content_key 解密 data.biz_content
  4. 解析解密后的业务 JSON。

明文 POST 不支持

当前协议不接受明文 POST 业务 JSON。明文调用会返回业务错误,例如:

json
{
  "code": 11015,
  "msg": "Open API 请求体必须是加密信封",
  "data": null
}

GET 不加密

GET 查询类接口只签名、不加密。平台不会在 GET 响应中返回收款账号、证件号、手机号等敏感原文。