提交 8a896eee 作者: 方治民

feat: 新增 jasypt 依赖并提供两个示例接口便于调试加解密参数配置

上级 5a637ba1
......@@ -83,4 +83,7 @@ dependencies {
// loki 日志推送
implementation "com.github.piomin:loki-logging-spring-boot-starter:${lokiLoggingVersion}"
// 配置加密
implementation "com.github.ulisesbocchio:jasypt-spring-boot-starter:${jasyptVersion}"
}
......@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
@Validated
@ApiSupport(order = -99999)
@Tag(name = "Health", description = "Health")
@RequestMapping("/")
@RequestMapping("/health")
@RestController
@RequiredArgsConstructor
public class HealthController {
......@@ -36,7 +36,7 @@ public class HealthController {
@SaIgnore
@Operation(summary = "健康检查")
@GetMapping("health")
@GetMapping
public Result<JSONObject> health(HttpServletResponse response) {
JSONObject data = new JSONObject();
boolean health = true;
......
/* (C) 2025 YiRing, Inc. */
package com.yiring.app.web.common;
import cn.dev33.satoken.annotation.SaIgnore;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.yiring.common.core.Result;
import com.yiring.common.param.InputParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Jim
*/
@Slf4j
@Validated
@ApiSupport(order = -99998)
@Tag(name = "Jasypt", description = "Jasypt")
@RequestMapping("/jasypt/")
@RestController
@RequiredArgsConstructor
public class JasyptController {
final StringEncryptor encryptor;
@SaIgnore
@Operation(summary = "加密字符串")
@PostMapping("encrypt")
public Result<String> encrypt(@ParameterObject @Validated InputParam param) {
String encrypt = encryptor.encrypt(param.getInput());
return Result.ok(encrypt);
}
@SaIgnore
@Operation(summary = "解密字符串")
@PostMapping("decrypt")
public Result<String> decrypt(@ParameterObject @Validated InputParam param) {
String decrypt = encryptor.decrypt(param.getInput());
return Result.ok(decrypt);
}
}
......@@ -19,5 +19,11 @@ spring:
include: auth, conf-patch #, conf-xxl-job, monitor
active: dev-postgresql
# 加密配置(生产环境应使用环境变量注入)
# https://www.cnblogs.com/larrydpk/p/12037857.html
jasypt:
encryptor:
password: KhJeJHnEPe2oo6d8
# DEBUG
debug: false
......@@ -68,6 +68,8 @@ ext {
ip2regionVersion = '2.7.0'
// https://central.sonatype.com/artifact/com.github.piomin/loki-logging-spring-boot-starter
lokiLoggingVersion = '2.0.3'
// https://central.sonatype.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter
jasyptVersion = '3.0.5'
// https://central.sonatype.com/artifact/net.bramp.ffmpeg/ffmpeg
// FIXED: ffmpeg 4.x
ffmpegWrapperVersion = '0.8.0'
......
/* (C) 2021 YiRing, Inc. */
package com.yiring.common.param;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import java.io.Serial;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.FieldDefaults;
/**
* 公共的输入参数
*
* @author ifzm
* @version 0.1
* 2022/4/27 08:53
*/
@Schema(name = "InputParam", description = "公共的输入参数")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class InputParam implements Serializable {
@Serial
private static final long serialVersionUID = -8690942241103456895L;
@Parameter(description = "输入值", example = "value")
@NotBlank
String input;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论