1446 fix: 修复API响应加密时添加加密 header 标识不生效的问题

This commit is contained in:
YunaiV 2025-11-21 20:11:24 +08:00
parent 1e76214362
commit 073ad8798c

View File

@ -42,16 +42,15 @@ public class ApiEncryptResponseWrapper extends HttpServletResponseWrapper {
this.flushBuffer();
byte[] body = byteArrayOutputStream.toByteArray();
// 2. 加密 body
String encryptedBody = symmetricEncryptor != null ? symmetricEncryptor.encryptBase64(body)
: asymmetricEncryptor.encryptBase64(body, KeyType.PublicKey);
// 3. 添加加密 header 标识设置header要放在response的write之前
// 2. 添加加密 header 标识
this.addHeader(properties.getHeader(), "true");
// 特殊特殊https://juejin.cn/post/6867327674675625992
this.addHeader("Access-Control-Expose-Headers", properties.getHeader());
// 4. 输出加密后的 body
// 3.1 加密 body
String encryptedBody = symmetricEncryptor != null ? symmetricEncryptor.encryptBase64(body)
: asymmetricEncryptor.encryptBase64(body, KeyType.PublicKey);
// 3.2 输出加密后的 body设置 header 要放在 response write 之前
response.getWriter().write(encryptedBody);
}