Commit d35e0281 by Simon Cheng

铭感字段加密

parent f830c9fe
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
......
package com.ajb.car;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ajb.car.vo.zhima.user.UserdataRequestVO;
@RestController
public class DataController {
/**
* 批处理表中的一列,多列
* @param userdataRequestVO
* @return
* @throws Exception
*/
@RequestMapping("/batch")
public Object query(@RequestBody UserdataRequestVO userdataRequestVO) throws Exception{
return null;
}
}
package com.ajb.car;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ajb.car.user.UserdataWebService;
import com.ajb.car.vo.common.DESCommon;
import com.ajb.car.vo.common.JsonResult;
import com.ajb.car.vo.zhima.user.UserdataRequestVO;
import com.ajb.car.vo.zhima.user.UserdataResponseVO;
import com.ajb.common.utils.encryption.DESUtils;
@RestController
@RequestMapping("/userdata")
public class UserdataController {
@Autowired
private UserdataWebService userdataWebService;
@RequestMapping("/userdataQuery")
public Object query(@RequestBody UserdataRequestVO userdataRequestVO) throws Exception{
JsonResult result = new JsonResult();
UserdataResponseVO userdataResponseVO = userdataWebService.userdataQuery(userdataRequestVO);
result.setData(userdataResponseVO);
return result;
}
@RequestMapping("/userdataSave")
public Object save(@RequestBody UserdataRequestVO userdataRequestVO) throws Exception{
JsonResult result = new JsonResult();
UserdataResponseVO userdataResponseVO = userdataWebService.userdataSave(userdataRequestVO);
result.setData(userdataResponseVO);
return result;
}
@RequestMapping("/userdataUpdate")
public Object update(@RequestBody UserdataRequestVO userdataRequestVO) throws Exception{
JsonResult result = new JsonResult();
UserdataResponseVO userdataResponseVO = userdataWebService.userdataUpdate(userdataRequestVO);
result.setData(userdataResponseVO);
return result;
}
@RequestMapping("/userdataEncrypt")
public Object encrypt(@RequestBody DESCommon requestVO) throws Exception{
JsonResult result = new JsonResult();
DESUtils des;
String resultString = "";
try {
des = new DESUtils("123456789", "utf-8");
//des = new DESUtils(jpaSensitiveSetting.sensitivekey, "utf-8");
resultString = des.encode(requestVO.getContent());
requestVO.setEncrypted(resultString);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result.setData(requestVO);
return result;
}
@RequestMapping("/userdataDecrypt")
public Object Decrypt(@RequestBody DESCommon requestVO) throws Exception{
JsonResult result = new JsonResult();
DESUtils des;
String content = "";
try {
des = new DESUtils("123456789", "utf-8");
//des = new DESUtils(jpaSensitiveSetting.sensitivekey, "utf-8");
content = des.decode(requestVO.getEncrypted());
requestVO.setContent(content);;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result.setData(requestVO);
return result;
}
}
\ No newline at end of file
package com.ajb.car.quotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ajb.car.vo.quotation.AgPoQuotationRequestVO;
import com.ajb.common.utils.encryption.MaskUtils;
@RestController
public class QuotationController {
@Autowired
private AgPoQuotationWebService agPoQuotationWebService;
@RequestMapping(value="/quotations/{quotationId}", method=RequestMethod.GET)
public AgPoQuotationRequestVO queryAgPoQuotation(@PathVariable String quotationId, Model model) throws Exception{
AgPoQuotationRequestVO quotationResponse= agPoQuotationWebService.queryAgPoQuotation(Long.valueOf(quotationId));
quotationResponse.setCustomerMobileMask(MaskUtils.maskCellphone(quotationResponse.getCustomerMobile()));
model.addAttribute("quotation", quotationResponse);
return quotationResponse;
}
}
\ No newline at end of file
package com.ajb.car.user;
import com.ajb.car.vo.zhima.user.UserdataRequestVO;
import com.ajb.car.vo.zhima.user.UserdataResponseVO;
public interface UserdataWebService {
public UserdataResponseVO userdataSave(UserdataRequestVO userdataRequestVO) throws Exception;
public UserdataResponseVO userdataUpdate(UserdataRequestVO userdataRequestVO);
public UserdataResponseVO userdataQuery(UserdataRequestVO userdataRequestVO);
//public boolean userdataDelete(UserdataDeleteRequestVO userdataDeleteRequestVO);
}
\ No newline at end of file
package com.ajb.car.user.impl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ajb.car.entity.meta.Userdata;
import com.ajb.car.metadata.service.UserdataService;
import com.ajb.car.user.UserdataWebService;
import com.ajb.car.vo.common.CommonResult;
import com.ajb.car.vo.zhima.user.UserdataDeleteRequestVO;
import com.ajb.car.vo.zhima.user.UserdataRequestVO;
import com.ajb.car.vo.zhima.user.UserdataResponseVO;
import com.ajb.common.utils.encryption.MaskUtils;
@Service("userdataWebService")
public class UserdataWebServiceImpl implements UserdataWebService {
@Autowired
private UserdataService userdataService;
@Transactional
@Override
public UserdataResponseVO userdataSave(UserdataRequestVO userdataRequestVO) throws Exception {
UserdataResponseVO result = new UserdataResponseVO();
//TODO validate the user inputs
Userdata tempEntity = new Userdata();
//TODO validate the user inputs
BeanUtils.copyProperties(userdataRequestVO,tempEntity);
//data persistence
tempEntity = userdataService.save(tempEntity);
//return success info
Boolean success = true;
String message = "save success!";
BeanUtils.copyProperties(tempEntity,userdataRequestVO);
result.setCommonResult(new CommonResult(success,message));
result.setRequestVO(userdataRequestVO);
return result;
}
@Transactional
@Override
public UserdataResponseVO userdataUpdate(UserdataRequestVO userdataRequestVO) {
// TODO Auto-generated method stub
Boolean success = true;
String message = "save success!";
UserdataResponseVO result = new UserdataResponseVO();
result.setCommonResult(new CommonResult(success,message));
return result;
}
@Transactional
@Override
public UserdataResponseVO userdataQuery(UserdataRequestVO userdataRequestVO) {
// TODO Auto-generated method stub
Boolean success = true;
String message = "save success!";
Userdata tempEntity = new Userdata();
//TODO validate the user inputs
BeanUtils.copyProperties(userdataRequestVO,tempEntity);
//data persistence
tempEntity = userdataService.findById(userdataRequestVO.getId());
UserdataResponseVO result = new UserdataResponseVO();
BeanUtils.copyProperties(tempEntity,userdataRequestVO);
userdataRequestVO.setIdnumbermask(MaskUtils.maskIDCardNo(userdataRequestVO.getIdnumber()));
userdataRequestVO.setTelephonemask(MaskUtils.maskCellphone(userdataRequestVO.getTelephone()));
result.setRequestVO(userdataRequestVO);
result.setCommonResult(new CommonResult(success,message));
return result;
}
}
\ No newline at end of file
encryption.key=12345678
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_121"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
...@@ -17,5 +17,12 @@ ...@@ -17,5 +17,12 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/ajb-car-utils"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>
...@@ -16,17 +16,17 @@ ...@@ -16,17 +16,17 @@
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name> <name>org.eclipse.wst.validation.validationbuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name> <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
......
disabled=06target
eclipse.preferences.version=1
package com.ajb.car.entity.meta;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="userdata")
public class Userdata implements java.io.Serializable {
private static final long serialVersionUID = 1L;
/** ?? 主键,???? ag_md_code_type.id */
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Long id;
@Column(name="username")
private String username;
@Column(name="pasword")
private String pasword;
@Column(name="encryptedpassword")
@Convert(converter = com.ajb.common.utils.encryption.JPACryptoConverter.class)
private String encryptedpassword;
@Column(name="telephone")
@Convert(converter = com.ajb.common.utils.encryption.JPACryptoConverter.class)
private String telephone;
@Column(name="idnumber")
@Convert(converter = com.ajb.common.utils.encryption.JPACryptoConverter.class)
private String idnumber;
public String getUsername(){
return this.username;
}
public void setUsername(String username){
this.username = username;
}
public String getPasword(){
return this.pasword;
}
public void setPasword(String pasword){
this.pasword = pasword;
}
public String getEncryptedpassword(){
return this.encryptedpassword;
}
public void setEncryptedpassword(String encryptedpassword){
this.encryptedpassword = encryptedpassword;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getIdnumber() {
return idnumber;
}
public void setIdnumber(String idnumber) {
this.idnumber = idnumber;
}
}
\ No newline at end of file
...@@ -12,9 +12,20 @@ ...@@ -12,9 +12,20 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> <classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes> <attributes>
<attribute name="owner.project.facets" value="java"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
......
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8
encoding/pom.xml=UTF-8 encoding/pom.xml=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.source=1.8
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="ajb-car-jpa"> <wb-module deploy-name="ajb-car-jpa">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/.apt_generated"/>
</wb-module> </wb-module>
</project-modules> </project-modules>
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
<faceted-project> <faceted-project>
<installed facet="cloudfoundry.standalone.app" version="1.0"/> <installed facet="cloudfoundry.standalone.app" version="1.0"/>
<installed facet="jst.utility" version="1.0"/> <installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="1.6"/> <installed facet="java" version="1.8"/>
</faceted-project> </faceted-project>
disabled=06target
eclipse.preferences.version=1
eclipse.preferences.version=1
userprojectsettings=false
package com.ajb.car.metadata.repositories;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.ajb.car.entity.meta.Userdata;
@Repository
public interface UserdataRepository extends JpaRepository<Userdata, Long>,JpaSpecificationExecutor<Userdata> {
/***
* mock find 10
*/
@Query(value="select * from ${context.tableName} t limit 10 ", nativeQuery=true)
List<Userdata> findAll();
}
\ No newline at end of file
package com.ajb.car.metadata.service;
import java.util.List;
import org.springframework.data.domain.Sort;
import com.ajb.car.entity.meta.Userdata;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface UserdataService {
Userdata save(Userdata userdata);
Boolean delete (Long id);
Userdata update(Userdata userdata);
Userdata findById(Long id);
Page<Userdata> findByObjPageable(Userdata userdata,Pageable pageable);
List<Userdata> findByObjSortable(Userdata userdata,Sort sort);
}
\ No newline at end of file
package com.ajb.car.metadata.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import com.ajb.car.entity.meta.Userdata;
import com.ajb.car.metadata.repositories.UserdataRepository;
import com.ajb.car.metadata.service.UserdataService;
@Service("userdataService")
public class UserdataServiceImpl implements UserdataService{
@Autowired
private UserdataRepository userdataRepo;
public Userdata save(Userdata obj){
return userdataRepo.save(obj);
}
public Boolean delete(Long id) {
try {
userdataRepo .delete(id);
} catch (Exception e) {
return false;
}
return true;
}
public Userdata update(Userdata obj) {
return userdataRepo.saveAndFlush(obj);
}
public Userdata findById(Long id){
return userdataRepo.findOne(id);
}
public Page<Userdata> findByObjPageable(Userdata obj,Pageable pageable){
ExampleMatcher matcher = ExampleMatcher.matching();
Example<Userdata> ex = Example.of(obj, matcher);
return userdataRepo.findAll(ex,pageable);
}
public List<Userdata> findByObjSortable(Userdata obj,Sort sort){
ExampleMatcher matcher = ExampleMatcher.matching();
Example<Userdata> ex = Example.of(obj, matcher);
return userdataRepo.findAll(ex,sort);
}
}
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_121"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
...@@ -17,5 +17,11 @@ ...@@ -17,5 +17,11 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>
...@@ -16,17 +16,23 @@ ...@@ -16,17 +16,23 @@
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>org.eclipse.wst.validation.validationbuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name> <name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
......
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/java/com/ajb/common/utils/string/StringUtil.java=UTF-8 encoding//src/main/java/com/ajb/common/utils/string/StringUtil.java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8
disabled=06target
eclipse.preferences.version=1
package com.ajb.common.utils.encryption;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* 加密/解密工具
* @author ershuai
* @date 2017年4月18日 上午11:27:36
*/
public class DESUtils {
private final byte[] DESIV = new byte[] { 0x12, 0x34, 0x56, 120, (byte) 0x90, (byte) 0xab, (byte) 0xcd, (byte) 0xef };// 向量
private AlgorithmParameterSpec iv = null;// 加密算法的参数接口
private Key key = null;
private String charset = "utf-8";
/**
* 初始化
* @param deSkey 密钥
* @return
* @throws Exception
*/
public DESUtils(String deSkey, String charset) throws Exception {
if (charset!=null && !charset.isEmpty())
{
this.charset = charset;
}
DESKeySpec keySpec = new DESKeySpec(deSkey.getBytes(this.charset));// 设置密钥参数
iv = new IvParameterSpec(DESIV);// 设置向量
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");// 获得密钥工厂
key = keyFactory.generateSecret(keySpec);// 得到密钥对象
}
/**
* 加密
* @author ershuai
* @date 2017年4月19日 上午9:40:53
* @param data
* @return
* @throws Exception
*/
public String encode(String data) throws Exception {
Cipher enCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");// 得到加密对象Cipher
enCipher.init(Cipher.ENCRYPT_MODE, key, iv);// 设置工作模式为加密模式,给出密钥和向量
byte[] pasByte = enCipher.doFinal(data.getBytes("utf-8"));
BASE64Encoder base64Encoder = new BASE64Encoder();
return base64Encoder.encode(pasByte);
}
/**
* 解密
* @author ershuai
* @date 2017年4月19日 上午9:41:01
* @param data
* @return
* @throws Exception
*/
public String decode(String data) throws Exception {
Cipher deCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
deCipher.init(Cipher.DECRYPT_MODE, key, iv);
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] pasByte = deCipher.doFinal(base64Decoder.decodeBuffer(data));
return new String(pasByte, "UTF-8");
}
public static void main(String[] args) {
try {
String test = "ershuai";
String key = "12345678";// 自定义密钥
DESUtils des = new DESUtils(key, "utf-8");
System.out.println("加密前的字符:" + test);
System.out.println("加密后的字符:" + des.encode(test));
System.out.println("解密后的字符:" + des.decode(des.encode(test)));
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.ajb.common.utils.encryption;
import java.util.Properties;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.apache.commons.lang3.StringUtils;
@Converter
public class JPACryptoConverter implements AttributeConverter<String, String> {
private static final String secret_property_key = "encryption.key";
private static final Properties properties = new Properties();
private static String sensitivekey = null;
static {
try {
properties.load(JPACryptoConverter.class.getClassLoader()
.getResourceAsStream("persistence.properties"));
} catch (Exception e) {
properties.put(secret_property_key, "12345678");
}
sensitivekey = (String)properties.get(secret_property_key);
}
@Override
public String convertToDatabaseColumn(String sensitive) {
DESUtils des;
String result = "";
try {
des = new DESUtils(sensitivekey, "utf-8");
if (StringUtils.isNotEmpty(sensitive) && StringUtils.isNoneBlank(sensitive))
{
result = des.encode(sensitive);
}
return result;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
@Override
public String convertToEntityAttribute(String sensitive) {
DESUtils des;
String result = "";
try {
des = new DESUtils(sensitivekey, "utf-8");
if (StringUtils.isNotEmpty(sensitive) && StringUtils.isNoneBlank(sensitive))
{
result = des.decode(sensitive);
}
return result;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
package com.ajb.common.utils.encryption;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* jwt安全验证设置 head tag,seal封条,过期时间,发行,bypass
* @author Simon Cheng
*/
@Service
public class JPASensitiveSetting {
@Value("${jpa.sensitivekey}")
public String sensitivekey;
}
package com.ajb.common.utils.encryption;
import org.apache.commons.lang3.StringUtils;
/**
*
*/
public class MaskUtils {
public static String maskCellphone(String cellphoneNo) {
if ((cellphoneNo == null) || (cellphoneNo.trim().length() != 11)) {
return cellphoneNo;
}
return cellphoneNo.substring(0, 3) + "****" + cellphoneNo.substring(cellphoneNo.length() - 4);
}
public static String maskEmail(String email) {
if (StringUtils.isBlank(email)) {
return "";
}
int index = StringUtils.indexOf(email, "@");
if (index <= 1)
return email;
else
return StringUtils.rightPad(StringUtils.left(email, 1), index, "*")
.concat(StringUtils.mid(email, index, StringUtils.length(email)));
}
private static String maskCardNo(String cardNo) {
if ((cardNo == null) || (cardNo.trim().length() <= 8)) {
return cardNo;
}
cardNo = cardNo.trim();
int length = cardNo.length();
String firstFourNo = cardNo.substring(0, 4);
String lastFourNo = cardNo.substring(length - 4);
String mask = "";
for (int i = 0; i < length - 8; i++) {
mask = mask + "*";
}
return firstFourNo + mask + lastFourNo;
}
public static String maskIDCardNo(String idCardNo) {
return maskCardNo(idCardNo);
}
public static String maskBankCardNo(String bankCardNo) {
return maskCardNo(bankCardNo);
}
}
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_121"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>org.eclipse.wst.validation.validationbuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name> <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
......
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/java/com/ajb/car/vo/common/JsonResult.java=UTF-8 encoding//src/main/java/com/ajb/car/vo/common/JsonResult.java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8
disabled=06target
eclipse.preferences.version=1
package com.ajb.car.vo.common;
import java.io.Serializable;
public class DESCommon implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String content;
private String encrypted;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getEncrypted() {
return encrypted;
}
public void setEncrypted(String encrypt) {
encrypted = encrypt;
}
}
package com.ajb.car.vo.quotation;
import com.ajb.car.vo.common.CommonResult;
public class AgPoQuotationResponseVO implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private CommonResult commonResult;
private AgPoQuotationRequestVO vo;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public CommonResult getCommonResult() {
return commonResult;
}
public void setCommonResult(CommonResult commonResult) {
this.commonResult = commonResult;
}
public AgPoQuotationRequestVO getRequestVO() {
return vo;
}
public void setRequestVO(AgPoQuotationRequestVO vo) {
this.vo = vo;
}
}
\ No newline at end of file
package com.ajb.car.vo.zhima.user;
public class UserdataDeleteRequestVO implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String pasword;
private String encryptedpassword;
private String telephone;
private String idnumber;
public void setUsername(String username){
this.username = username;
}
public String getUsername(){
return this.username;
}
public void setPasword(String pasword){
this.pasword = pasword;
}
public String getPasword(){
return this.pasword;
}
public void setEncryptedpassword(String encryptedpassword){
this.encryptedpassword = encryptedpassword;
}
public String getEncryptedpassword(){
return this.encryptedpassword;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getIdnumber() {
return idnumber;
}
public void setIdnumber(String idnumber) {
this.idnumber = idnumber;
}
}
\ No newline at end of file
package com.ajb.car.vo.zhima.user;
public class UserdataRequestVO implements java.io.Serializable {
/**
* 用户数据
*/
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String pasword;
private String encryptedpassword;
private String telephone;
private String idnumber;
private String telephonemask;
private String idnumbermask;
public void setUsername(String username){
this.username = username;
}
public String getUsername(){
return this.username;
}
public void setPasword(String pasword){
this.pasword = pasword;
}
public String getPasword(){
return this.pasword;
}
public void setEncryptedpassword(String encryptedpassword){
this.encryptedpassword = encryptedpassword;
}
public String getEncryptedpassword(){
return this.encryptedpassword;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getIdnumber() {
return idnumber;
}
public void setIdnumber(String idnumber) {
this.idnumber = idnumber;
}
public String getTelephonemask() {
return telephonemask;
}
public void setTelephonemask(String telephonemask) {
this.telephonemask = telephonemask;
}
public String getIdnumbermask() {
return idnumbermask;
}
public void setIdnumbermask(String idnumbermask) {
this.idnumbermask = idnumbermask;
}
}
\ No newline at end of file
package com.ajb.car.vo.zhima.user;
import com.ajb.car.vo.common.CommonResult;
public class UserdataResponseVO implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private CommonResult commonResult;
private UserdataRequestVO vo;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public CommonResult getCommonResult() {
return commonResult;
}
public void setCommonResult(CommonResult commonResult) {
this.commonResult = commonResult;
}
public UserdataRequestVO getRequestVO() {
return vo;
}
public void setRequestVO(UserdataRequestVO vo) {
this.vo = vo;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment