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

ep api鉴权修改

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