refactor: 适配 ContiNew Starter 加密模块(安全模块)

This commit is contained in:
2024-02-08 23:19:37 +08:00
parent 2109789116
commit 6435175dc3
10 changed files with 89 additions and 27 deletions

View File

@@ -96,6 +96,12 @@
<artifactId>continew-starter-file-excel</artifactId>
</dependency>
<!-- ContiNew Starter 安全模块 - 加密 -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-security-crypto</artifactId>
</dependency>
<!-- ContiNew Starter 安全模块 - 脱敏 -->
<dependency>
<groupId>top.charles7c.continew</groupId>

View File

@@ -0,0 +1,29 @@
package top.charles7c.continew.admin.common.config.mybatis;
import org.springframework.security.crypto.password.PasswordEncoder;
import top.charles7c.continew.starter.security.crypto.encryptor.IEncryptor;
/**
* BCrypt 加/解密处理器(不可逆)
*
* @author Charles7c
* @since 2024/2/8 22:29
*/
public class BCryptEncryptor implements IEncryptor {
private final PasswordEncoder passwordEncoder;
public BCryptEncryptor(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}
@Override
public String encrypt(String plaintext, String password, String publicKey) throws Exception {
return passwordEncoder.encode(plaintext);
}
@Override
public String decrypt(String ciphertext, String password, String privateKey) throws Exception {
return ciphertext;
}
}

View File

@@ -21,6 +21,7 @@ import org.springframework.context.annotation.Configuration;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.springframework.security.crypto.password.PasswordEncoder;
import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermissionFilter;
/**
@@ -47,4 +48,12 @@ public class MybatisPlusConfiguration {
public DataPermissionFilter dataPermissionFilter() {
return new DataPermissionFilterImpl();
}
/**
* BCrypt 加/解密处理器
*/
@Bean
public BCryptEncryptor bCryptEncryptor(PasswordEncoder passwordEncoder) {
return new BCryptEncryptor(passwordEncoder);
}
}

View File

@@ -31,7 +31,7 @@ public class RsaProperties {
public static final String PRIVATE_KEY;
static {
PRIVATE_KEY = SpringUtil.getProperty("rsa.privateKey");
PRIVATE_KEY = SpringUtil.getProperty("continew-starter.security.crypto.private-key");
}
private RsaProperties() {