Commit 74b9352c authored by eddie.woo's avatar eddie.woo

ep api鉴权修改

parent 546c3c49
package pwc.taxtech.atms.security.dd; package pwc.taxtech.atms.security.dd;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -6,12 +7,8 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -6,12 +7,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import pwc.taxtech.atms.exception.ServiceException; import pwc.taxtech.atms.exception.ServiceException;
import pwc.taxtech.atms.service.impl.ProjectServiceImpl; import pwc.taxtech.atms.service.impl.ProjectServiceImpl;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
//import org.apache.tomcat.util.codec.binary.Base64;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
...@@ -20,6 +17,7 @@ import java.text.SimpleDateFormat; ...@@ -20,6 +17,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
/** /**
* @Auther: Gary J Li * @Auther: Gary J Li
* @Date: 20/03/2019 20:41 * @Date: 20/03/2019 20:41
...@@ -47,11 +45,9 @@ public class DtsTokenService { ...@@ -47,11 +45,9 @@ public class DtsTokenService {
* @throws * @throws
*/ */
public String encryptInput(){ public String encryptInput(){
BASE64Encoder base64 = new BASE64Encoder();
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] encodeData; byte[] encodeData;
try { try {
byte[] publicKey = base64Decoder.decodeBuffer(pubKey); byte[] publicKey = Base64.decodeBase64(pubKey);
String nonce = generateNonce(); String nonce = generateNonce();
String sDate = generateDate(); String sDate = generateDate();
long rNum = generateRandomNumber(); long rNum = generateRandomNumber();
...@@ -59,12 +55,12 @@ public class DtsTokenService { ...@@ -59,12 +55,12 @@ public class DtsTokenService {
byte[] data1 = inputStr1.getBytes(); byte[] data1 = inputStr1.getBytes();
logger.debug("原文:" + inputStr1); logger.debug("原文:" + inputStr1);
encodeData = encryptByPublicKey(data1, publicKey); encodeData = encryptByPublicKey(data1, publicKey);
logger.debug("公钥加密后:" + base64.encode(encodeData)); logger.debug("公钥加密后:" + Base64.encodeBase64String(encodeData));
} catch (Exception ex) { } catch (Exception ex) {
throw new ServiceException("cus" + ex); throw new ServiceException("cus" + ex);
} }
return base64.encode(encodeData); return Base64.encodeBase64String(encodeData);
} }
......
...@@ -2,7 +2,6 @@ package pwc.taxtech.atms.service.impl; ...@@ -2,7 +2,6 @@ package pwc.taxtech.atms.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import org.junit.Test; import org.junit.Test;
...@@ -12,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import pwc.taxtech.atms.CommonIT; import pwc.taxtech.atms.CommonIT;
import pwc.taxtech.atms.common.AuthUserHelper; import pwc.taxtech.atms.common.AuthUserHelper;
import pwc.taxtech.atms.common.schedule.OrgSyncJob;
import pwc.taxtech.atms.common.util.BaseThreadFactory; import pwc.taxtech.atms.common.util.BaseThreadFactory;
import pwc.taxtech.atms.common.util.DateUtils; import pwc.taxtech.atms.common.util.DateUtils;
import pwc.taxtech.atms.common.util.HttpUtil; import pwc.taxtech.atms.common.util.HttpUtil;
...@@ -30,8 +28,6 @@ import pwc.taxtech.atms.entity.*; ...@@ -30,8 +28,6 @@ import pwc.taxtech.atms.entity.*;
import pwc.taxtech.atms.exception.ServiceException; import pwc.taxtech.atms.exception.ServiceException;
import pwc.taxtech.atms.security.dd.DtsTokenService; import pwc.taxtech.atms.security.dd.DtsTokenService;
import pwc.taxtech.atms.service.EbsApiService; import pwc.taxtech.atms.service.EbsApiService;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.crypto.Cipher; import javax.crypto.Cipher;
...@@ -712,11 +708,9 @@ public class EbsApiServiceImplTest extends CommonIT { ...@@ -712,11 +708,9 @@ public class EbsApiServiceImplTest extends CommonIT {
public String encryptInput(){ public String encryptInput(){
BASE64Encoder base64 = new BASE64Encoder();
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] encodeData; byte[] encodeData;
try { try {
byte[] publicKey = base64Decoder.decodeBuffer("MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKUfMPRKV6I5num1dDWcxTrgTjXf5LctsVj0CpbwHE83mmjUO5CAlvA0Fwy30ajCX5sLmsyi+Eu/4uNmM6GQF3kCAwEAAQ=="); byte[] publicKey = org.apache.commons.codec.binary.Base64.decodeBase64("MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKUfMPRKV6I5num1dDWcxTrgTjXf5LctsVj0CpbwHE83mmjUO5CAlvA0Fwy30ajCX5sLmsyi+Eu/4uNmM6GQF3kCAwEAAQ==");
String nonce = generateNonce(); String nonce = generateNonce();
String sDate = generateDate(); String sDate = generateDate();
long rNum = generateRandomNumber(); long rNum = generateRandomNumber();
...@@ -724,12 +718,11 @@ public class EbsApiServiceImplTest extends CommonIT { ...@@ -724,12 +718,11 @@ public class EbsApiServiceImplTest extends CommonIT {
byte[] data1 = inputStr1.getBytes(); byte[] data1 = inputStr1.getBytes();
logger.debug("原文:" + inputStr1); logger.debug("原文:" + inputStr1);
encodeData = encryptByPublicKey(data1, publicKey); encodeData = encryptByPublicKey(data1, publicKey);
logger.debug("公钥加密后:" + base64.encode(encodeData));
} catch (Exception ex) { } catch (Exception ex) {
throw new ServiceException("cus" + ex); throw new ServiceException("cus" + ex);
} }
return base64.encode(encodeData); return org.apache.commons.codec.binary.Base64.encodeBase64String(encodeData);
} }
...@@ -737,7 +730,7 @@ public class EbsApiServiceImplTest extends CommonIT { ...@@ -737,7 +730,7 @@ public class EbsApiServiceImplTest extends CommonIT {
private String generateNonce() throws Exception { private String generateNonce() throws Exception {
String dateTimeString = Long.toString(System.currentTimeMillis()); String dateTimeString = Long.toString(System.currentTimeMillis());
byte[] nonceByte = dateTimeString.getBytes(); byte[] nonceByte = dateTimeString.getBytes();
return Base64.encodeBase64String(nonceByte); return Base64.getEncoder().encodeToString(nonceByte);
} }
private String generateDate() throws Exception { private String generateDate() throws Exception {
......
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