Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
b0513f09
Commit
b0513f09
authored
Jun 27, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表结构修改
parent
d048f8a5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
10 deletions
+30
-10
RsaHelper.java
.../src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
+7
-8
TestRsa.java
yzg-util-base/src/test/java/helper/TestRsa.java
+23
-2
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
View file @
b0513f09
...
...
@@ -373,12 +373,7 @@ public final class RsaHelper {
*/
public
static
String
decodeRsaValueInfo
(
String
rsaJsonPwd
,
PublicKey
publicKey
,
long
timeout
)
{
String
rsaJson
=
decryptionByPublicKey
(
rsaJsonPwd
,
publicKey
);
RsaValueInfo
rsaValueInfo
=
JsonHelper
.
deserialize
(
rsaJson
,
RsaValueInfo
.
class
);
long
splitTime
=
rsaValueInfo
.
getT
()
-
System
.
currentTimeMillis
()
/
1000
;
if
(
splitTime
>
timeout
)
{
throw
new
RuntimeCodeException
(
"056"
,
"解密超时"
);
}
return
rsaValueInfo
.
getV
();
return
checkTimeout
(
timeout
,
rsaJson
);
}
/**
...
...
@@ -391,9 +386,13 @@ public final class RsaHelper {
*/
public
static
String
decodeRsaValueInfo
(
String
rsaJsonPwd
,
PrivateKey
privateKey
,
long
timeout
)
{
String
rsaJson
=
decryptionByPrivateKey
(
rsaJsonPwd
,
privateKey
);
return
checkTimeout
(
timeout
,
rsaJson
);
}
private
static
String
checkTimeout
(
long
timeout
,
String
rsaJson
)
{
RsaValueInfo
rsaValueInfo
=
JsonHelper
.
deserialize
(
rsaJson
,
RsaValueInfo
.
class
);
long
splitTime
=
rsaValueInfo
.
getT
()
-
System
.
currentTimeMillis
()
/
1000
;
if
(
splitTime
>
timeout
)
{
long
splitTime
=
System
.
currentTimeMillis
()
/
1000
-
rsaValueInfo
.
getT
()
;
if
(
splitTime
>
timeout
&&
timeout
>
0
)
{
throw
new
RuntimeCodeException
(
"056"
,
"解密超时"
);
}
return
rsaValueInfo
.
getV
();
...
...
yzg-util-base/src/test/java/helper/TestRsa.java
View file @
b0513f09
package
helper
;
import
com.yanzuoguang.util.helper.RsaHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -42,10 +43,20 @@ public class TestRsa {
Assert
.
assertEquals
(
from
,
result
);
String
rsaTemp
=
RsaHelper
.
encodeRsaValueInfo
(
from
,
rsaInfo
.
getPublicKeyFrom
());
String
rsaResult
=
RsaHelper
.
decodeRsaValueInfo
(
rsaTemp
,
rsaInfo
.
getPrivateKeyFrom
(),
10
*
100
0
);
String
rsaResult
=
RsaHelper
.
decodeRsaValueInfo
(
rsaTemp
,
rsaInfo
.
getPrivateKeyFrom
(),
0
);
System
.
out
.
println
(
"Json时间公钥加密后字段:"
+
rsaTemp
);
System
.
out
.
println
(
"Json时间私钥解密后字段:"
+
rsaResult
);
Assert
.
assertEquals
(
from
,
rsaResult
);
ThreadHelper
.
sleep
(
2000
);
boolean
isOk
=
false
;
try
{
String
rsaResult1
=
RsaHelper
.
decodeRsaValueInfo
(
rsaTemp
,
rsaInfo
.
getPrivateKeyFrom
(),
1
);
isOk
=
true
;
}
catch
(
Exception
ex
)
{
System
.
err
.
println
(
ex
.
getMessage
());
}
Assert
.
assertFalse
(
isOk
);
}
...
...
@@ -64,9 +75,19 @@ public class TestRsa {
Assert
.
assertEquals
(
from
,
result
);
String
rsaTemp
=
RsaHelper
.
encodeRsaValueInfo
(
from
,
rsaInfo
.
getPrivateKeyFrom
());
String
rsaResult
=
RsaHelper
.
decodeRsaValueInfo
(
rsaTemp
,
rsaInfo
.
getPublicKeyFrom
(),
10
*
100
0
);
String
rsaResult
=
RsaHelper
.
decodeRsaValueInfo
(
rsaTemp
,
rsaInfo
.
getPublicKeyFrom
(),
0
);
System
.
out
.
println
(
"Json时间公钥加密后字段:"
+
rsaTemp
);
System
.
out
.
println
(
"Json时间私钥解密后字段:"
+
rsaResult
);
Assert
.
assertEquals
(
from
,
rsaResult
);
ThreadHelper
.
sleep
(
2000
);
boolean
isOk
=
false
;
try
{
RsaHelper
.
decodeRsaValueInfo
(
rsaTemp
,
rsaInfo
.
getPublicKeyFrom
(),
1
);
isOk
=
true
;
}
catch
(
Exception
ex
)
{
System
.
err
.
println
(
ex
.
getMessage
());
}
Assert
.
assertFalse
(
isOk
);
}
}
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