身份证手机号加密

l
862857010@qq.com 2 years ago
parent 55364e3219
commit aa10527a31
  1. 2
      src/main/java/com/cjy/back/ybsjAppointment/dao/YbsjyAppointmentRecordMapper.xml
  2. 104
      src/main/java/com/cjy/back/ybsjAppointment/service/impl/YbsjyAppointmentRecordImpl.java
  3. 43
      src/main/java/com/cjy/back/ybsjAppointment/service/impl/YbsjyAppointmentSettingServiceImpl.java
  4. 13
      src/main/java/com/cjy/back/ybsjAppointment/task/ClearVisitorInformationTask.java
  5. 7
      src/main/java/com/cjy/back/ybsjAppointment/task/ExtractWriteOffRecordsTask.java
  6. 158
      src/main/java/com/cjy/back/ybsjAppointment/utils/Encryption.java
  7. 19
      src/main/java/com/cjy/back/ybsjAppointment/utils/IdProduceUtil.java
  8. 3
      src/main/resources/application-prod.properties

@ -295,7 +295,7 @@
SELECT id,
documents_number as documentsNumber
FROM ybsj_appointment_people_info
WHERE clear_visitors = 0
WHERE clear_visitors = 0 and documents_type=5501
</select>
<select id="getProcessRequestFailRecordList" resultType="java.util.Map">
SELECT

@ -8,6 +8,8 @@ import com.cjy.back.ybsjAppointment.entity.vo.AppointmentDocumentsDetails;
import com.cjy.back.ybsjAppointment.entity.vo.AppointmentPersonVO;
import com.cjy.back.ybsjAppointment.entity.vo.GetAppointmentRecordVO;
import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentRecordService;
import com.cjy.back.ybsjAppointment.utils.Encryption;
import com.cjy.back.ybsjAppointment.utils.IdProduceUtil;
import com.cjy.common.PageWrapper;
import com.cjy.util.HttpUtil;
import com.cjy.util.ServerResponse;
@ -44,6 +46,8 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
@Value("${jqzhgk.synchronousCancelDataUrl}")
private String synchronousCancelDataUrl;
@Value("${encryptionRule}")
private String rule;
/**
* 查询预约记录
@ -53,6 +57,7 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
*/
@Override
public ServerResponse getAppointmentRecord(GetAppointmentRecordVO getAppointmentRecordVO) {
// 获取当前页码,在分页组件里 参数固定为currentPage
String cpage = getAppointmentRecordVO.getPage();
// 显示行数
@ -66,12 +71,13 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
pw.getPage().setCurrentPage(pageNo);
pw.getPage().setPageSize(limit); // 每页条数
/* 分页信息结束 */
if (getAppointmentRecordVO.getReservationPersonPhone()!=null) {
getAppointmentRecordVO.setReservationPersonPhone(Encryption.encrypt(getAppointmentRecordVO.getReservationPersonPhone(), rule));
}
//根据条件进行分页查询数据
List<Map<String, Object>> list = ybsjyAppointmentRecordMapper.getAppointmentRecordListByPage(pw.getPage(), getAppointmentRecordVO);
// list.stream().forEach(item -> {
//
// });
// 查询总行数
int userCount = pw.getPage().getTotalCount();
//返回数据
@ -106,23 +112,23 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
public ServerResponse cancelAppointment(Long id, int userId) {
// //第一步修改取消单状态
// ybsjyAppointmentRecordMapper.updateCancelDocuments(id, userId+"");
if(ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsIdWriteOffCount(id)==0){
if (ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsIdWriteOffCount(id) == 0) {
//第一步修改取消单状态
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, userId+"","3");
}else {
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, userId+"","1");
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, userId + "", "3");
} else {
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, userId + "", "1");
}
List<String> appointmentPeopleIds=ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsId(id);
List<String> appointmentPeopleIds = ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsId(id);
//第二步修改预约单下人的状态
//通过单号获取到所有取消的数据id
ybsjyAppointmentRecordMapper.updateAppointmentPeopleInfo(id, userId+"");
ybsjyAppointmentRecordMapper.updateAppointmentPeopleInfo(id, userId + "");
String responseString = HttpUtil.sendPostJson(synchronousCancelDataUrl, JSONObject.toJSONString(appointmentPeopleIds));
String responseString = HttpUtil.sendPostJson(synchronousCancelDataUrl, JSONObject.toJSONString(appointmentPeopleIds));
JSONObject responseJson = JSONObject.parseObject(responseString);
//记录访问日志
AppointmentRequestTurnstileLogEntity appointmentRequestTurnstileLogEntity = new AppointmentRequestTurnstileLogEntity();
appointmentRequestTurnstileLogEntity.setRequestUrl(synchronousCancelDataUrl);
appointmentRequestTurnstileLogEntity.setRequestParams( JSONObject.toJSONString(appointmentPeopleIds));
appointmentRequestTurnstileLogEntity.setRequestParams(JSONObject.toJSONString(appointmentPeopleIds));
appointmentRequestTurnstileLogEntity.setResponseBody(responseString);
appointmentRequestTurnstileLogEntity.setState(responseJson.get("code").toString());
appointmentRequestTurnstileLogEntity.setType("post");
@ -134,30 +140,31 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
/**
* 小程序取消预约
*
* @param id
* @param unionId
* @return
*/
@Override
public ServerResponse cancelAppointment(Long id, String unionId) {
if(ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsIdWriteOffCount(id)==0){
//第一步修改取消单状态
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, unionId,"3");
}else {
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, unionId,"1");
}
List<String> appointmentPeopleIds=ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsId(id);
if (ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsIdWriteOffCount(id) == 0) {
//第一步修改取消单状态
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, unionId, "3");
} else {
ybsjyAppointmentRecordMapper.updateCancelDocuments(id, unionId, "1");
}
List<String> appointmentPeopleIds = ybsjyAppointmentRecordMapper.getAppointmentPeopleIdByDocumentsId(id);
//第二步修改预约单下人的状态
ybsjyAppointmentRecordMapper.updateAppointmentPeopleInfo(id, unionId);
//通过单号获取到所有取消的数据id
String responseString = HttpUtil.sendPostJson(synchronousCancelDataUrl, JSONObject.toJSONString(appointmentPeopleIds));
String responseString = HttpUtil.sendPostJson(synchronousCancelDataUrl, JSONObject.toJSONString(appointmentPeopleIds));
JSONObject responseJson = JSONObject.parseObject(responseString);
//记录访问日志
AppointmentRequestTurnstileLogEntity appointmentRequestTurnstileLogEntity = new AppointmentRequestTurnstileLogEntity();
appointmentRequestTurnstileLogEntity.setRequestUrl(synchronousCancelDataUrl);
appointmentRequestTurnstileLogEntity.setRequestParams( JSONObject.toJSONString(appointmentPeopleIds));
appointmentRequestTurnstileLogEntity.setRequestParams(JSONObject.toJSONString(appointmentPeopleIds));
appointmentRequestTurnstileLogEntity.setResponseBody(responseString);
appointmentRequestTurnstileLogEntity.setState(responseJson.get("code").toString());
appointmentRequestTurnstileLogEntity.setType("post");
@ -178,6 +185,16 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
List<AppointmentPersonVO> list = ybsjyAppointmentRecordMapper.getAppointmentPersonInfo(id);
//获取人信息
list.stream().forEach(item -> {
if (item.getDocumentsType() == 5501) {
String documentsNumber = Encryption.decrypt(item.getDocumentsNumber(), rule);
item.setDocumentsNumber(IdProduceUtil.desensitizeIDCard(documentsNumber));
}
if (!item.getPhone().isEmpty()) {
String phone = Encryption.decrypt(item.getPhone(), rule);
item.setPhone(IdProduceUtil.desensitizePhoneNumber(phone));
}
});
appointmentDocumentsDetails.setList(list);
return ServerResponse.createBySuccess(appointmentDocumentsDetails);
}
@ -198,7 +215,7 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
int endIndex = Math.min(startIndex + pageSize, list.size());
sheet.setDefaultRowHeightInPoints(18);
sheet.setDefaultColumnWidth(12);
sheet.setColumnWidth(10, (int) (128 *(40+0.72)));
sheet.setColumnWidth(10, (int) (128 * (40 + 0.72)));
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setBorderBottom(BorderStyle.THIN);
@ -230,8 +247,6 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
cellStyleTable.setFont(font);
HSSFRow row1 = sheet.createRow(0);
String[] headerinfo = new String[]{"预约单号", "景区名称", "预约日期", "预约时段", "预约人姓名", "预约人手机号", "证件类型", "证件号码", "预约码", "状态", "核销时间"};
for (int b = 0; b < headerinfo.length; b++) {
@ -246,7 +261,7 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
HSSFCell cell = row.createCell(0);
cell.setCellValue(data.get("appointmentNumber").toString());
cell.setCellStyle(cellStyle);
cell = row.createCell(1);
cell.setCellStyle(cellStyle);
cell.setCellValue(data.get("scenicName").toString());
@ -265,7 +280,13 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
cell = row.createCell(5);
cell.setCellStyle(cellStyle);
cell.setCellValue(data.get("phone").toString());
if (!data.get("phone").toString().isEmpty()) {
String phone = Encryption.decrypt(data.get("phone").toString(), rule);
cell.setCellValue(IdProduceUtil.desensitizePhoneNumber(phone));
} else {
cell.setCellValue(data.get("phone").toString());
}
cell = row.createCell(6);
cell.setCellStyle(cellStyle);
@ -273,20 +294,26 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
cell = row.createCell(7);
cell.setCellStyle(cellStyle);
cell.setCellValue(data.get("documentsNumber").toString());
if (data.get("documentsType").toString().equals("身份证")) {
String documentsNumber = Encryption.decrypt(data.get("documentsNumber").toString(), rule);
cell.setCellValue(IdProduceUtil.desensitizeIDCard(documentsNumber));
} else {
cell.setCellValue(data.get("documentsNumber").toString());
}
cell = row.createCell(8);
cell.setCellStyle(cellStyle);
cell.setCellValue(data.get("reservationCode").toString());
String state="";
if(data.get("state").toString().equals("0")){
state="未核销";
}else if(data.get("state").toString().equals("1")){
state="已核销";
}else {
state="取消";
String state = "";
if (data.get("state").toString().equals("0")) {
state = "未核销";
} else if (data.get("state").toString().equals("1")) {
state = "已核销";
} else {
state = "取消";
}
cell = row.createCell(9);
cell.setCellStyle(cellStyle);
@ -319,6 +346,7 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
/**
* 修改预约单状态
*
* @param id
* @return
*/
@ -329,6 +357,7 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
/**
* 获取未核销数量
*
* @param id
* @return
*/
@ -340,25 +369,28 @@ public class YbsjyAppointmentRecordImpl implements YbsjyAppointmentRecordService
/**
* 修改预约单状态
*
* @param id
* @return
*/
@Override
public int updateDocumentsSate(Long id,int state) {
return ybsjyAppointmentRecordMapper.updateDocumentsSate(id,state);
public int updateDocumentsSate(Long id, int state) {
return ybsjyAppointmentRecordMapper.updateDocumentsSate(id, state);
}
/**
* 获取当天已核销或者取消的数据
*
* @return
*/
@Override
public List<Map<String,Object> > getWrittenOffAppointmentData() {
public List<Map<String, Object>> getWrittenOffAppointmentData() {
return ybsjyAppointmentRecordMapper.getWrittenOffAppointmentData();
}
/**
* 修改数据清除状态
*
* @param ids
* @return
*/

@ -11,6 +11,7 @@ import com.cjy.back.ybsjAppointment.entity.vo.*;
import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentSettingService;
import com.cjy.back.ybsjAppointment.utils.AppointmentNumberUtil;
import com.cjy.back.ybsjAppointment.utils.DateUtil;
import com.cjy.back.ybsjAppointment.utils.Encryption;
import com.cjy.back.ybsjAppointment.utils.IdProduceUtil;
import com.cjy.common.PageWrapper;
import com.cjy.util.HttpUtil;
@ -35,7 +36,8 @@ public class YbsjyAppointmentSettingServiceImpl implements YbsjyAppointmentSetti
YbsjyAppointmentSettingMapper ybsjyAppointmentSettingMapper;
@Autowired
YbsjyAppointmentRecordMapper ybsjyAppointmentRecordMapper;
@Value("${encryptionRule}")
private String rule;
@Value("${turnstile.url}")
private String turnstileUrl;
@ -311,9 +313,18 @@ public class YbsjyAppointmentSettingServiceImpl implements YbsjyAppointmentSetti
synchronousDataVO.setAppointmentDate(item.getAppointmentDate());
synchronousDataVO.setAppointmentSlot(reservationNowVO.getStartTime() + "~" + reservationNowVO.getEndTime());
synchronousDataVO.setAppointmentPeopleName(item.getName());
synchronousDataVO.setAppointmentPeoplePhone(item.getPhone());
if(!item.getPhone().isEmpty()){
synchronousDataVO.setAppointmentPeoplePhone(Encryption.encrypt(item.getPhone(),rule));
}
synchronousDataVO.setCertificateType(item.getDocumentsType() + "");
synchronousDataVO.setDocumentsNumber(item.getDocumentsNumber());
if(item.getDocumentsType()==5501){
String documentsNumber= Encryption.encrypt(item.getDocumentsNumber(),rule);
synchronousDataVO.setDocumentsNumber(documentsNumber);
}else {
synchronousDataVO.setDocumentsNumber(item.getDocumentsNumber());
}
synchronousDataVO.setState("0");
synchronousDataVO.setDataSources("2");
synchronousDataVO.setDelFlag("0");
@ -372,6 +383,17 @@ public class YbsjyAppointmentSettingServiceImpl implements YbsjyAppointmentSetti
// ybsjyAppointmentSettingMapper.saveAppointmentRequestTurnstileLog(appointmentRequestTurnstileLogEntity);
// item.setQrContent(json1.get("二维码信息").toString());
});
reservationNowVO.getAppointmentPersonList().stream().forEach(i -> {
if(i.getDocumentsType()==5501){
String documentsNumber= Encryption.encrypt(i.getDocumentsNumber(),rule);
i.setDocumentsNumber(documentsNumber);
}else {
i.setDocumentsNumber(i.getDocumentsNumber());
}
if(!i.getPhone().isEmpty()){
i.setPhone(Encryption.encrypt(i.getPhone(),rule));
}
});
ybsjyAppointmentSettingMapper.saveAppointmentPeopleInfo(reservationNowVO.getAppointmentPersonList());
@ -414,9 +436,7 @@ public class YbsjyAppointmentSettingServiceImpl implements YbsjyAppointmentSetti
//根据条件进行分页查询数据
List<Map<String, Object>> list = ybsjyAppointmentRecordMapper.getappletsAppointmentRecordListByPage(pw.getPage(), getAppointmentRecordVO);
list.stream().forEach(item -> {
});
// 查询总行数
int userCount = pw.getPage().getTotalCount();
//返回数据
@ -441,6 +461,16 @@ public class YbsjyAppointmentSettingServiceImpl implements YbsjyAppointmentSetti
AppointmentDocumentsDetails appointmentDocumentsDetails = ybsjyAppointmentRecordMapper.getAppletsAppointmentDocumentsInfo(id);
List<AppointmentPersonVO> list = ybsjyAppointmentRecordMapper.getAppointmentPersonInfo(id);
list.stream().forEach(item->{
if(item.getDocumentsType()==5501){
String documentsNumber = Encryption.decrypt(item.getDocumentsNumber(), rule);
item.setDocumentsNumber(IdProduceUtil.desensitizeIDCard(documentsNumber));
}
if(!item.getPhone().isEmpty()){
String phone = Encryption.decrypt(item.getPhone(), rule);
item.setPhone(IdProduceUtil.desensitizePhoneNumber(phone));
}
});
//获取人信息
appointmentDocumentsDetails.setList(list);
return ServerResponse.createBySuccess(appointmentDocumentsDetails);
@ -459,7 +489,8 @@ public class YbsjyAppointmentSettingServiceImpl implements YbsjyAppointmentSetti
appointmentWriteOffLogEntity.setTime(time);
appointmentWriteOffLogEntity.setIdCard(idCard);
try {
Map<String, Object> map = ybsjyAppointmentRecordMapper.getAppointmentPeopleInfo(formattedDate, idCard);
String newIdCard= Encryption.encrypt(idCard,rule);
Map<String, Object> map = ybsjyAppointmentRecordMapper.getAppointmentPeopleInfo(formattedDate, newIdCard);
ybsjyAppointmentRecordMapper.writeOff(time, map.get("id").toString());
List<SynchronousWriteOffDataVO> synchronousWriteOffDataVOS= new ArrayList<>();

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import com.cjy.back.ybsjAppointment.dao.YbsjyAppointmentSettingMapper;
import com.cjy.back.ybsjAppointment.entity.AppointmentRequestTurnstileLogEntity;
import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentRecordService;
import com.cjy.back.ybsjAppointment.utils.Encryption;
import com.cjy.back.ybsjAppointment.utils.IdProduceUtil;
import com.cjy.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -31,7 +33,8 @@ public class ClearVisitorInformationTask {
private String turnstileUrl;
@Value("${turnstile.clearSingleVisitor}")
private String clearSingleVisitor;
@Value("${encryptionRule}")
private String rule;
@Scheduled(cron = "0 0/45 * * * ?")
// @Scheduled(cron = "0 0/1 * * * ?")
public void clearVisitorInformationTask() {
@ -39,11 +42,15 @@ public class ClearVisitorInformationTask {
List<Map<String, Object>> list = ybsjyAppointmentRecordService.getWrittenOffAppointmentData();
List<String> ids = new ArrayList<>();
list.stream().forEach(item -> {
String addVisitorResponseString = HttpUtil.doGet(turnstileUrl+clearSingleVisitor + "?idCard=" + item.get("documentsNumber"));
String documentsNumber = Encryption.decrypt(item.get("documentsNumber").toString(), rule);
String addVisitorResponseString = HttpUtil.doGet(turnstileUrl+clearSingleVisitor + "?idCard=" + documentsNumber);
JSONObject addVisitorResponseJson = JSONObject.parseObject(addVisitorResponseString);
//记录访问日志
AppointmentRequestTurnstileLogEntity appointmentRequestTurnstileLogEntity = new AppointmentRequestTurnstileLogEntity();
appointmentRequestTurnstileLogEntity.setRequestUrl(turnstileUrl+clearSingleVisitor + "?idCard=" + item.get("documentsNumber"));
appointmentRequestTurnstileLogEntity.setRequestUrl(turnstileUrl+clearSingleVisitor + "?idCard=" + documentsNumber);
appointmentRequestTurnstileLogEntity.setType("get");
appointmentRequestTurnstileLogEntity.setResponseBody(addVisitorResponseString);
appointmentRequestTurnstileLogEntity.setState(addVisitorResponseJson.get("code").toString());

@ -8,6 +8,7 @@ import com.cjy.back.ybsjAppointment.entity.AppointmentRequestTurnstileLogEntity;
import com.cjy.back.ybsjAppointment.entity.AppointmentWriteOffLogEntity;
import com.cjy.back.ybsjAppointment.entity.vo.ExtractRecordsDataVO;
import com.cjy.back.ybsjAppointment.entity.vo.SynchronousWriteOffDataVO;
import com.cjy.back.ybsjAppointment.utils.Encryption;
import com.cjy.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -38,7 +39,8 @@ public class ExtractWriteOffRecordsTask {
@Value("${jqzhgk.synchronousWriteOffDataUrl}")
private String synchronousWriteOffDataUrl;
@Value("${encryptionRule}")
private String rule;
@Scheduled(cron = "0 0/50 * * * ?")
// @Scheduled(cron = "0 0/1 * * * ?")
/**
@ -63,7 +65,8 @@ public class ExtractWriteOffRecordsTask {
SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String time = item.getTime();
String idCard = item.getIdCard();
String documentsNumber= Encryption.encrypt(item.getIdCard(),rule);
String idCard = documentsNumber;
Date date = null;
try {

@ -0,0 +1,158 @@
package com.cjy.back.ybsjAppointment.utils;
import org.apache.commons.lang.StringUtils;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
/**
* @author liangjiawei
* @createDate 2023/7/17
*/
public class Encryption {
/**
* 加解密密钥, 外部可以
*/
public static final String AES_DATA_SECURITY_KEY = "4%YkW!@g5LGcf9Ut";
/**
* 算法/加密模式/填充方式
*/
private static final String AES_PKCS5P = "AES/ECB/PKCS5Padding";
private static final String AES_PERSON_KEY_SECURITY_KEY = "pisnyMyZYXuCNcRd";
/**
* 加密
*
* @param str
* 需要加密的字符串
* @param key
* 密钥
* @return
* @throws Exception
*/
public static String encrypt(String str, String key) {
if (StringUtils.isEmpty(key)) {
throw new RuntimeException("key不能为空");
}
try {
if (str == null) {
return null;
}
// 判断Key是否为16位
if (key.length() != 16) {
return null;
}
byte[] raw = key.getBytes(StandardCharsets.UTF_8);
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
// "算法/模式/补码方式"
Cipher cipher = Cipher.getInstance(AES_PKCS5P);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(str.getBytes(StandardCharsets.UTF_8));
// 使用Base64进行URL安全编码
return Base64.getUrlEncoder().encodeToString(encrypted);
} catch (Exception ex) {
return null;
}
}
/**
* 解密
*
* @param str 需要解密的字符串
* @param key 密钥
* @return
*/
public static String decrypt(String str, String key) {
if (StringUtils.isEmpty(key)) {
throw new IllegalArgumentException("key不能为空");
}
try {
if (StringUtils.isEmpty(str)) {
return null;
}
// 判断Key是否为16位
if (key.getBytes(StandardCharsets.UTF_8).length != 16) {
return null;
}
byte[] raw = key.getBytes(StandardCharsets.UTF_8);
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance(AES_PKCS5P);
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
// 先用base64解密
byte[] encrypted = Base64.getUrlDecoder().decode(str);
try {
byte[] original = cipher.doFinal(encrypted);
return new String(original, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new RuntimeException("解密失败", e);
}
} catch (Exception ex) {
throw new RuntimeException("解密失败", ex);
}
}
/**
* 加密
*
* @param str 需要加密的字符串
* @return
* @throws Exception
*/
public static String encrypt(String str) {
return encrypt(str,AES_DATA_SECURITY_KEY);
}
/**
* 解密
* @param str 需要解密的字符串
* @return
*/
public static String decrypt(String str) {
return decrypt(str,AES_DATA_SECURITY_KEY);
}
/**
* 查询的时候对某些字段解密
*
* @param str
* @return
*/
public static String aesDecrypt(String str) {
if (StringUtils.isBlank(str)) {
return " ";
}
String sql = " AES_DECRYPT(from_base64(" + str + ")," + "'" + AES_DATA_SECURITY_KEY + "')";
return sql;
}
/**
* 对personKey加密
*
* @param personKey
* @return
*/
public static String encryptPersonKey(String personKey) {
return encrypt(personKey, AES_PERSON_KEY_SECURITY_KEY);
}
/**
* 对personKey解密
*
* @param personKey
* @return
*/
public static String decryptPersonKey(String personKey) {
return decrypt(personKey, AES_PERSON_KEY_SECURITY_KEY);
}
public static void main(String[] args) {
System.out.println(encrypt("3261015184","Xt9saen8xKY3eSmb"));
System.out.println(decrypt("sgU2EbT-lORewPaFztQKPg==","Xt9saen8xKY3eSmb"));
}
}

@ -277,4 +277,23 @@ public class IdProduceUtil {
Random random=new Random();
return Long.parseLong(System.currentTimeMillis()+String.format("%03d", random.nextInt(999)), 10);
}
public static String desensitizeIDCard(String idCard) {
int startIndex = 3; // 需要隐藏的起始位置
int endIndex = 14; // 需要隐藏的结束位置
StringBuilder sb = new StringBuilder(idCard);
for (int i = startIndex; i < endIndex; i++) {
sb.setCharAt(i, '*'); // 使用*替换数字
}
return sb.toString();
}
public static String desensitizePhoneNumber(String phoneNumber) {
int startIndex = 3; // 需要隐藏的起始位置
int endIndex = 7; // 需要隐藏的结束位置
StringBuilder sb = new StringBuilder(phoneNumber);
for (int i = startIndex; i < endIndex; i++) {
sb.setCharAt(i, '*'); // 使用*替换数字
}
return sb.toString();
}
}

@ -207,4 +207,5 @@ jqzhgk.organCode=123
jqzhgk.synchronousDataUrl=http://127.0.0.1:8096/reservationdata/appointmentrecord/synchronousData
jqzhgk.synchronousWriteOffDataUrl=http://127.0.0.1:8096/reservationdata/appointmentrecord/synchronousWriteOffData
jqzhgk.synchronousCancelDataUrl=http://127.0.0.1:8096/reservationdata/appointmentrecord/synchronousCancelData
jqzhgk.complanit=http://127.0.0.1:8096/marketingData/complaint/synchronous
jqzhgk.complanit=http://127.0.0.1:8096/marketingData/complaint/synchronous
encryptionRule=Xt9saen8xKY3eSmb
Loading…
Cancel
Save