Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
szpt
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
以墨为白
szpt
Commits
212d9fbd
Commit
212d9fbd
authored
Jan 12, 2025
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加密优化
parent
a55e27c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
12 deletions
+16
-12
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
...ava/com/zksy/szpt/filter/SignatureVerificationFilter.java
+4
-3
src/test/java/com/zksy/szpt/TestAppStore.java
src/test/java/com/zksy/szpt/TestAppStore.java
+9
-6
src/test/java/com/zksy/szpt/TestHttpUtil.java
src/test/java/com/zksy/szpt/TestHttpUtil.java
+3
-3
No files found.
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
View file @
212d9fbd
...
@@ -116,8 +116,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
...
@@ -116,8 +116,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
// 校验appId
// 校验appId
AppStore
appStore
=
this
.
appStoreService
.
getAppSecretInfo
(
appId
);
AppStore
appStore
=
this
.
appStoreService
.
getAppSecretInfo
(
appId
);
String
appSecret
=
appStore
.
getAppSecret
();
if
(
appStore
==
null
||
appStore
.
getAppSecret
()
==
null
)
{
if
(!
StringUtils
.
hasText
(
appSecret
))
{
this
.
write
(
response
,
"appId无效:"
+
appId
);
this
.
write
(
response
,
"appId无效:"
+
appId
);
return
false
;
return
false
;
}
}
...
@@ -134,10 +133,12 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
...
@@ -134,10 +133,12 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
logger
.
info
(
"请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}, deptCode: {}"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
logger
.
info
(
"请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}, deptCode: {}"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
String
appSecret
=
appStore
.
getAppSecret
();
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
// logger.info("appSecret
{}加密后body: {}", appSecret,body);
logger
.
info
(
"appSecret:
{}加密后body: {}"
,
appSecret
,
body
);
// 校验签名appId+nonce+timestampStr+aes(body,secret)+detCode
// 校验签名appId+nonce+timestampStr+aes(body,secret)+detCode
String
data
=
String
.
format
(
"%s%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
String
data
=
String
.
format
(
"%s%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
logger
.
info
(
"待签名数据:{}"
,
data
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
if
(!
generatedSignature
.
equals
(
sign
))
{
if
(!
generatedSignature
.
equals
(
sign
))
{
logger
.
warn
(
"签名有误,generatedSignature:{},sign:{},appId:{},nonce:{},timestampStr:{},deptCode:{}"
,
generatedSignature
,
sign
,
appId
,
nonce
,
timestampStr
,
deptCode
);
logger
.
warn
(
"签名有误,generatedSignature:{},sign:{},appId:{},nonce:{},timestampStr:{},deptCode:{}"
,
generatedSignature
,
sign
,
appId
,
nonce
,
timestampStr
,
deptCode
);
...
...
src/test/java/com/zksy/szpt/TestAppStore.java
View file @
212d9fbd
...
@@ -15,13 +15,16 @@ public class TestAppStore {
...
@@ -15,13 +15,16 @@ public class TestAppStore {
@Test
@Test
@DisplayName
(
"新增AppId"
)
@DisplayName
(
"新增AppId"
)
public
void
addAppId
()
{
public
void
addAppId
()
{
AppStoreDTO
appStoreDTO
=
new
AppStoreDTO
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
appStoreDTO
.
setAppKey
(
"scale"
);
AppStoreDTO
appStoreDTO
=
new
AppStoreDTO
();
appStoreDTO
.
setAppSecret
(
DigestUtil
.
md5Hex
(
"scale"
));
appStoreDTO
.
setAppKey
(
"scale"
);
appStoreDTO
.
setDeptCode
(
"3302020201"
);
appStoreDTO
.
setAppSecret
(
DigestUtil
.
md5Hex
(
"scale"
));
appStoreDTO
.
setDeptCode
(
"330102"
);
TestHttpUtil
.
signatureAndRequest
(
"/rest/appStore/updateAppIdSecret"
,
appStoreDTO
,
AppStoreDTO
.
class
);
TestHttpUtil
.
signatureAndRequest
(
"/rest/appStore/insertAppStore"
,
appStoreDTO
,
AppStoreDTO
.
class
);
TestHttpUtil
.
signatureAndRequest
(
"/rest/appStore/insertAppStore"
,
appStoreDTO
,
AppStoreDTO
.
class
);
}
// TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO, AppStoreDTO.class);
// TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO);
// TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO);
}
}
...
...
src/test/java/com/zksy/szpt/TestHttpUtil.java
View file @
212d9fbd
...
@@ -14,9 +14,9 @@ public class TestHttpUtil {
...
@@ -14,9 +14,9 @@ public class TestHttpUtil {
private
static
final
org
.
slf4j
.
Logger
log
=
org
.
slf4j
.
LoggerFactory
.
getLogger
(
TestHttpUtil
.
class
);
private
static
final
org
.
slf4j
.
Logger
log
=
org
.
slf4j
.
LoggerFactory
.
getLogger
(
TestHttpUtil
.
class
);
static
String
nonce
=
"2"
;
static
String
nonce
=
"2"
;
static
String
timestampStr
=
"21"
;
static
String
timestampStr
=
"21"
;
static
String
appId
=
"
scale
"
;
static
String
appId
=
"
1872576325743943682
"
;
static
String
appSecret
=
DigestUtil
.
md5Hex
(
"
scale
"
);;
static
String
appSecret
=
DigestUtil
.
md5Hex
(
"
2
"
);;
static
String
deptCode
=
"330
2020201
"
;
static
String
deptCode
=
"330
102
"
;
private
static
final
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
static
final
ObjectMapper
objectMapper
=
new
ObjectMapper
();
...
...
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