车辆管理-手机号、车牌号加密存储
This commit is contained in:
parent
e64207f70b
commit
f7329039c6
|
|
@ -1,7 +1,10 @@
|
|||
package com.securitycontrol.common.core.utils.aes;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
|
|
@ -211,6 +214,21 @@ public class SM4Utils {
|
|||
return decryptData(CBC, cipherText, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密未加密的数据
|
||||
* @param data
|
||||
* @return String
|
||||
* @date 2024/9/12 10:37
|
||||
*/
|
||||
public static String encryptData(String data) {
|
||||
String lm = "щ";
|
||||
String value = decryptData_CBC(data);
|
||||
if(StringUtils.isBlank(value) || Objects.equals(lm,value)){
|
||||
return encryptData_CBC(data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// System.out.println("经过ECB加密的密文为:" + SM4Utils.encryptData_ECB("41150320000416041X"));
|
||||
// System.out.println("经过ECB解密的密文为:" + SM4Utils.decryptData_ECB("ZaCySfpl8DLflqpnM67eqBuFHqHevz6NvJY7i77t4zk="));
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.securitycontrol.background.mapper.VehicleMapper;
|
|||
import com.securitycontrol.background.service.VehicleService;
|
||||
import com.securitycontrol.common.core.constant.Constant;
|
||||
import com.securitycontrol.common.core.utils.aes.DateTimeHelper;
|
||||
import com.securitycontrol.common.core.utils.aes.SM4Utils;
|
||||
import com.securitycontrol.common.core.utils.uuid.IdUtils;
|
||||
import com.securitycontrol.entity.background.dto.VehicleDto;
|
||||
import com.securitycontrol.entity.background.vo.UserAccessVo;
|
||||
|
|
@ -44,6 +45,10 @@ public class VehicleServiceImpl implements VehicleService {
|
|||
List<VehicleVo> list = new ArrayList<>();
|
||||
try {
|
||||
list = mapper.getVehicleLists(dto);
|
||||
list.forEach(item->{
|
||||
item.setCarNum(SM4Utils.encryptData(item.getCarNum()));
|
||||
item.setPhone(SM4Utils.encryptData(item.getPhone()));
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("获取车辆列表",e);
|
||||
}
|
||||
|
|
@ -66,6 +71,8 @@ public class VehicleServiceImpl implements VehicleService {
|
|||
} else {
|
||||
vo.setType(2);
|
||||
}
|
||||
vo.setCarNum(SM4Utils.encryptData(vo.getCarNum()));
|
||||
vo.setPhone(SM4Utils.encryptData(vo.getPhone()));
|
||||
mapper.addOrUpdateVehicle(vo);
|
||||
} catch (Exception e) {
|
||||
log.error("车辆新增/修改", e);
|
||||
|
|
@ -75,6 +82,13 @@ public class VehicleServiceImpl implements VehicleService {
|
|||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String data = SM4Utils.encryptData_CBC("18995451236");
|
||||
System.err.println("加密后:"+data);
|
||||
String decryptDataCbc = SM4Utils.decryptData_CBC("19159189428");
|
||||
System.err.println("解密后:"+decryptDataCbc);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param dto
|
||||
|
|
|
|||
Loading…
Reference in New Issue