Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
74b9352c
Commit
74b9352c
authored
Mar 26, 2019
by
eddie.woo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ep api鉴权修改
parent
546c3c49
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
19 deletions
+8
-19
DtsTokenService.java
...in/java/pwc/taxtech/atms/security/dd/DtsTokenService.java
+5
-9
EbsApiServiceImplTest.java
.../pwc/taxtech/atms/service/impl/EbsApiServiceImplTest.java
+3
-10
No files found.
atms-api/src/main/java/pwc/taxtech/atms/security/dd/DtsTokenService.java
View file @
74b9352c
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
);
}
...
...
atms-api/src/test/java/pwc/taxtech/atms/service/impl/EbsApiServiceImplTest.java
View file @
74b9352c
...
...
@@ -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
.
encodeBase64
String
(
nonceByte
);
return
Base64
.
getEncoder
().
encodeTo
String
(
nonceByte
);
}
private
String
generateDate
()
throws
Exception
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment