数据库字段加密,删除无用操作

pull/22/head
rays 2021-08-19 16:36:09 +08:00
parent be1e279f35
commit 9daebb9456
4 changed files with 6 additions and 65 deletions

View File

@ -31,14 +31,4 @@ public interface EncryptAlgorithmApi {
* @date 2021/7/3 11:33
**/
String decrypt(String cipher);
/**
*
* <p>
*
*
* @author majianguo
* @date 2021/7/19 10:04
**/
void setInstance(SymmetricCrypto instance);
}

View File

@ -2,8 +2,11 @@ package cn.stylefeng.roses.kernel.security.database.algorithm.impl;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.stylefeng.roses.kernel.security.api.expander.SecurityConfigExpander;
import cn.stylefeng.roses.kernel.security.database.algorithm.EncryptAlgorithmApi;
import java.nio.charset.StandardCharsets;
/**
* AES
*
@ -12,27 +15,15 @@ import cn.stylefeng.roses.kernel.security.database.algorithm.EncryptAlgorithmApi
*/
public class AesEncryptAlgorithmApiImpl implements EncryptAlgorithmApi {
/**
* AES
*/
public SymmetricCrypto symmetricCrypto;
public AesEncryptAlgorithmApiImpl(byte[] key) {
symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
}
@Override
public void setInstance(SymmetricCrypto instance) {
this.symmetricCrypto = instance;
}
@Override
public String encrypt(String encryptedData) {
SymmetricCrypto symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, SecurityConfigExpander.getEncryptSecretKey().getBytes(StandardCharsets.UTF_8));
return symmetricCrypto.encryptHex(encryptedData);
}
@Override
public String decrypt(String cipher) {
SymmetricCrypto symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, SecurityConfigExpander.getEncryptSecretKey().getBytes(StandardCharsets.UTF_8));
return symmetricCrypto.decryptStr(cipher);
}
}

View File

@ -1,36 +0,0 @@
package cn.stylefeng.roses.kernel.security.database.init;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.stylefeng.roses.kernel.config.api.ConfigInitCallbackApi;
import cn.stylefeng.roses.kernel.security.api.expander.SecurityConfigExpander;
import cn.stylefeng.roses.kernel.security.database.algorithm.EncryptAlgorithmApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
/**
*
*
* @author majianguo
* @date 2021/7/17 16:01
*/
@Component
public class DefaultConfigInitCallbackImpl implements ConfigInitCallbackApi {
@Autowired
private EncryptAlgorithmApi encryptAlgorithmApi;
@Override
public void initBefore() {
}
@Override
public void initAfter() {
// 修改数据库秘钥AES实例
SymmetricCrypto symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, SecurityConfigExpander.getEncryptSecretKey().getBytes(StandardCharsets.UTF_8));
encryptAlgorithmApi.setInstance(symmetricCrypto);
}
}

View File

@ -24,15 +24,12 @@
*/
package cn.stylefeng.roses.kernel.security.starter;
import cn.stylefeng.roses.kernel.security.api.expander.SecurityConfigExpander;
import cn.stylefeng.roses.kernel.security.database.algorithm.EncryptAlgorithmApi;
import cn.stylefeng.roses.kernel.security.database.algorithm.impl.AesEncryptAlgorithmApiImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.nio.charset.StandardCharsets;
/**
*
*
@ -52,8 +49,7 @@ public class EncryptAlgorithmAutoConfiguration {
@Bean
@ConditionalOnMissingBean(EncryptAlgorithmApi.class)
public EncryptAlgorithmApi encryptAlgorithmApi() {
String encryptSecretKey = SecurityConfigExpander.getEncryptSecretKey();
return new AesEncryptAlgorithmApiImpl(encryptSecretKey.getBytes(StandardCharsets.UTF_8));
return new AesEncryptAlgorithmApiImpl();
}
}