You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
4.2 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.general.Util"%>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="java.security.Key" %>
<%@ page import="javax.crypto.Cipher" %>
<%@ page import="javax.crypto.spec.IvParameterSpec" %>
<%@ page import="java.util.Base64" %>
<%@ page import="javax.crypto.spec.DESKeySpec" %>
<%@ page import="javax.crypto.SecretKeyFactory" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.net.URLEncoder" %>
<jsp:useBean id="ResourceComInfo" class="weaver.hrm.resource.ResourceComInfo" scope="page"/>
<%
String erphost = "http://cs.njycjt.com:9060";
String pageUrl = "/PubPlatform/Nav/Home/Default.aspx";
/**
* 偏移变量固定占8位字节
*/
String IV_PARAMETER = "njy(cjt(";
/**
* 密钥算法
*/
String ALGORITHM = "DES";
/**
* 加密/解密算法-工作模式-填充模式
*/
String CIPHER_ALGORITHM = "DES/CBC/PKCS5Padding";
/**
* 默认编码
*/
String CHARSET = "UTF-8";
String password = IV_PARAMETER ;
String msg = "" ;
String jumpUrl = "" ;
User user = HrmUserVarify.getUser (request,response);
if(user !=null){
String userid = user.getUID()+"";
String workcode = ResourceComInfo.getWorkcode(userid);
if(StringUtils.isNotBlank(password) && password.length()>=8){
if(StringUtils.isNotBlank(workcode)){
String encryptUser = encrypt(password,workcode,CHARSET,ALGORITHM,CIPHER_ALGORITHM,IV_PARAMETER);
long currentTimeMillis = System.currentTimeMillis();
long currentTimeSeconds = currentTimeMillis / 1000;
String encryptTime = encrypt(password,Util.null2String(currentTimeSeconds),CHARSET,ALGORITHM,CIPHER_ALGORITHM,IV_PARAMETER);
String encodeUser = URLEncoder.encode(encryptUser,"UTF-8");
String encodeTime = URLEncoder.encode(encryptTime,"UTF-8");
String encodePageUrl = URLEncoder.encode(pageUrl,"UTF-8");
jumpUrl = erphost+"/PubPlatform/Nav/Login/SSO/Login?UserCode="+encodeUser+"&PageUrl="+encodePageUrl+"&iat="+encodeTime;
}else{
msg = "获取当前用户工号为空";
}
}else{
msg = "加密秘钥为空或者秘钥少于8位";
}
}else{
msg = "获取当前用户为空";
}
if(StringUtils.isNotBlank(jumpUrl)){
response.sendRedirect(jumpUrl);
}
%>
<script type="text/javascript" src="<%=weaver.general.GCONST.getContextPath()%>/cloudstore/resource/pc/jquery/jquery.min.js"></script>
<script>
// window.location.href=viewUrl+"&returnUrl="+window.encodeURIComponent(returnUrl);
jQuery(document).ready(function () {
var msg = "<%=msg %>";
var jumpUrl = "<%=jumpUrl %>";
if(jumpUrl =="" && msg !=""){
alert(msg);
}
});
</script>
<%!
/**
* DES加密字符串
*
* @param password 加密密码长度不能够小于8位
* @param data 待加密字符串
* @return 加密后内容
*/
public String encrypt(String password, String data,String CHARSET,String ALGORITHM,String CIPHER_ALGORITHM,String IV_PARAMETER) {
String encrtptData = "" ;
if (StringUtils.isNotBlank(data)){
try {
DESKeySpec dks = new DESKeySpec(password.getBytes(CHARSET));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
Key secretKey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(IV_PARAMETER.getBytes(CHARSET));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
byte[] bytes = cipher.doFinal(data.getBytes(CHARSET));
//JDK1.8及以上可直接使用Base64JDK1.7及以下可以使用BASE64Encoder
//Android平台可以使用android.util.Base64
encrtptData = new String(Base64.getEncoder().encode(bytes));
} catch (Exception e) {
e.printStackTrace();
}
}
return encrtptData ;
}
%>