<span style="white-space:pre"> </span>/**
* <p>Description: 密码加密</p>
* @param Userpasword 传过来的六位数字密码
* @return 加密后的字符串
* @throws Exception
* @date: 2015年7月27日
*/
public String secretEncrypt(String Userpasword) throws Exception {
//使用Cipher的实例
Cipher cipher =Cipher.getInstance("AES");
//得到加密的钥匙
SecretKey key =KeyGenerator.getInstance("AES").generateKey();
//初始化加密操作,传递加密的钥匙
cipher.init(Cipher.ENCRYPT_MODE,key);
//将加密的内容传递进去,返回加密后的二进制数据
String results =cipher.doFinal(Userpasword.getBytes()).toString();
//返回加密后的字符串
return results;
}
<span style="white-space:pre"> </span>/**
* <p>Description: 保存用户基本信息</p>
* @param personBaseInfo 用户基本信息实体
* @return 布尔型,true代表添加成功,false代表添加失败
* @throws Exception
* @date: 2015年7月27日
*/
public boolean saveUserInformation(UserBaseInfo userBaseInfo) throws Exception{
boolean result = false;
try{
//保存用户基本信息
System.out.println("用户密码:" + secretEncrypt(userBaseInfo.getUserPassword()));
//给密码加密,然后放在实体里进行保存
userBaseInfo.setSUserPassword(secretEncrypt(userBaseInfo.getUserPassword()));
//保存用户信息
userBaseInfoService.save(userBaseInfo);
result = true;
}catch(Exception e){
e.printStackTrace();
}
return result;
}
<span style="font-size: 18px; white-space: pre;"> </span><span style="font-size:14px;">/**
* <p>Description: 解密函数</p>
* @param userPassword
* @return
* @throws Exception
* @author : gaoying
* @update :
* @date : 2015-7-27
*/
public String secretDecrypt(String userPassword) throws Exception{
//使用Cipher的实例
Cipher cipher =Cipher.getInstance("AES");
//获取文件中的key进行解密
FileInputStream fisKey=new FileInputStream("secretKey.key");
ObjectInputStream oisKey =new ObjectInputStream(fisKey);
Key key =(Key)oisKey.readObject();
oisKey.close();
fisKey.close();
//初始化解密操作,传递加密的钥匙
cipher.init(Cipher.DECRYPT_MODE,key);
//获取文件中的二进制数据
FileInputStream fisDat=new FileInputStream("secretContent.dat");
//获取数据
byte [] src=new byte [fisDat.available()];
int len =fisDat.read(src);
int total =0;
while(total<src.length){
total +=len;
len=fisDat.read(src,total,src.length-total);
}
//执行解密
String result=cipher.doFinal(src).toString();
return result;
}</span>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有