ソースを参照

CA密码加密

liuwenbin 7 年 前
コミット
75deaf6956

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java

@ -1470,6 +1470,7 @@ public class DoctorInfoService extends BaseService {
                String data = responseObject.getString("data");
                if("0".equals(data)){
                    Doctor doctor = findDoctorByCode(doctorCode);
                    strNewCalledPasswd = Base64Utils.encryptBASE64(strNewCalledPasswd);
                    doctor.setCheckPassword(strNewCalledPasswd);//保存密码,以便忘记密码时候使用
                    doctor.setIscertified(1);//说明已经(线上认证,已修改密码)
                    doctorDao.save(doctor);

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/jimeiJkEdu/JMJkEduArticleService.java

@ -1327,7 +1327,7 @@ public class JMJkEduArticleService extends BaseService {
            heapm.setLeaveWords(one.getLeaveWords());//医生留言
            doctor = doctorDao.findByCode(one.getDoctorCode());
            heapm.setPhoto(doctor.getPhoto());
//            heapm.setTotalData(total);
            heapm.setTotalData(total);
            result.add(heapm);
            // heapm.setTime();//时间  xx小时前  2017-10-11
        }

+ 21 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/Base64Utils.java

@ -1,14 +1,10 @@
package com.yihu.wlyy.util;
import org.apache.axis.encoding.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
/**
@ -141,4 +137,22 @@ public class Base64Utils {
		in.close();
	}
	//加密
	public static String encryptBASE64(String key) {
		byte[] bt = key.getBytes();
		return (new BASE64Encoder()).encodeBuffer(bt);
	}
	//解密
	public static String decryptBASE64(String key) {
		byte[] bt;
		try {
			bt = (new BASE64Decoder()).decodeBuffer(key);
			return new String(bt, "utf-8");//如果出现乱码可以改成: String(bt, "utf-8")或 gbk
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}

+ 23 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandingService.java

@ -11,6 +11,7 @@ import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.manage.UserDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.util.Base64Utils;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.LatitudeUtils;
import com.yihu.wlyy.util.MD5;
@ -20,6 +21,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
@ -43,6 +45,8 @@ public class DataHandingService {
    private ElastricSearchSave elastricSearchSave;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Transactional
    public String producePatientAndDoctorPassword() {
@ -190,4 +194,23 @@ public class DataHandingService {
        });
        return ja;
    }
    //原有CA的密码没有加密,清洗成加密密码
    public boolean updateCAPassword(){
        boolean flag = true;
        try {
            String sql = " select * from wlyy_doctor where check_password is not null and check_password <> ''";
            List<Doctor> list =  jdbcTemplate.queryForList(sql,Doctor.class);
            List<Doctor> result = new ArrayList<>();
            list.stream().forEach(one->{
                one.setCheckPassword(Base64Utils.encryptBASE64(one.getCheckPassword()));
                result.add(one);
            });
            doctorDao.save(result);
        }catch (Exception e){
            e.printStackTrace();
            flag = false;
        }
        return  flag;
    }
}

+ 12 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java

@ -264,4 +264,16 @@ public class DataHandlingController extends BaseController {
        return write(200, jsonObject.toString());
    }
    @RequestMapping(value = "/updateCAPassword", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("CA密码加密")
    public String updateCAPassword() {
        boolean flag = dataHandingService.updateCAPassword();
        if (flag) {
            return write(200, "清洗数据成功!");
        } else {
            return write(0, "清洗数据失败!");
        }
    }
}

+ 15 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -24,10 +24,7 @@ import com.yihu.wlyy.service.app.sign.FamilyContractService;
import com.yihu.wlyy.service.app.team.DrHealthTeamService;
import com.yihu.wlyy.service.common.account.RoleService;
import com.yihu.wlyy.service.common.account.TokenService;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.IdcardValidator;
import com.yihu.wlyy.util.RSAUtils;
import com.yihu.wlyy.util.*;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -1987,7 +1984,8 @@ public class DoctorController extends BaseController {
    public String installAuthenticationPassword(@RequestParam(value = "strNewCalledPasswd",required = true) String strNewCalledPasswd){
        try {
            Doctor doctor = doctorInfoService.findDoctorByCode(getUID());
            String strOldCalledPasswd = StringUtils.isNotEmpty(doctor.getCheckPassword())?doctor.getCheckPassword():"11111111";
            String strOldCalledPasswd = StringUtils.isNotEmpty(doctor.getCheckPassword())?doctor.getCheckPassword():Base64Utils.encryptBASE64("11111111");
            strOldCalledPasswd = Base64Utils.decryptBASE64(strOldCalledPasswd);
            boolean b = doctorInfoService.updateAuthenticationPassword(doctor.getIdcard(),strOldCalledPasswd,strNewCalledPasswd,getUID());
            if(b){
                return write(200, "设置密码成功!", "data", b);
@ -2138,5 +2136,17 @@ public class DoctorController extends BaseController {
            return error(-1, "获取失败!");
        }
    }
    public static void main(String[] args) {
        String aa = "111111";
//        String bb= MD5.GetMD5Code(aa);
//        System.out.printf(bb);
//        String cc= MD5.GetMD5Code(bb);
//        System.out.printf(cc);
        String bb = Base64Utils.encryptBASE64(aa);
        System.out.println(bb);
        String cc = Base64Utils.decryptBASE64(bb);
        System.out.println(cc);
    }
}