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
95d7f2f4
Commit
95d7f2f4
authored
Aug 17, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级新版本
parent
001cb613
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
11 deletions
+7
-11
RsaHelper.java
.../src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
+6
-10
TestRsa.java
yzg-util-base/src/test/java/helper/TestRsa.java
+1
-1
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
View file @
95d7f2f4
...
@@ -2,9 +2,7 @@ package com.yanzuoguang.util.helper;
...
@@ -2,9 +2,7 @@ package com.yanzuoguang.util.helper;
import
com.yanzuoguang.util.YzgError
;
import
com.yanzuoguang.util.YzgError
;
import
com.yanzuoguang.util.contants.SystemContants
;
import
com.yanzuoguang.util.contants.SystemContants
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.log.Log
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.Base64Utils
;
import
org.springframework.util.Base64Utils
;
import
javax.crypto.Cipher
;
import
javax.crypto.Cipher
;
...
@@ -34,8 +32,6 @@ import java.security.spec.X509EncodedKeySpec;
...
@@ -34,8 +32,6 @@ import java.security.spec.X509EncodedKeySpec;
*/
*/
public
final
class
RsaHelper
{
public
final
class
RsaHelper
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RsaHelper
.
class
);
private
static
final
String
ALGORITHM_RSA
=
"RSA"
;
private
static
final
String
ALGORITHM_RSA
=
"RSA"
;
private
static
final
String
ALGORITHM_SIGN
=
"MD5withRSA"
;
private
static
final
String
ALGORITHM_SIGN
=
"MD5withRSA"
;
...
@@ -96,10 +92,10 @@ public final class RsaHelper {
...
@@ -96,10 +92,10 @@ public final class RsaHelper {
byte
[]
keyBs
=
rsaPublicKey
.
getEncoded
();
byte
[]
keyBs
=
rsaPublicKey
.
getEncoded
();
String
publicKey
=
encodeBase64
(
keyBs
);
String
publicKey
=
encodeBase64
(
keyBs
);
logger
.
info
(
"生成的公钥:\t{}
"
,
publicKey
);
Log
.
info
(
RsaHelper
.
class
,
"生成的公钥:\t %s
"
,
publicKey
);
keyBs
=
rsaPrivateKey
.
getEncoded
();
keyBs
=
rsaPrivateKey
.
getEncoded
();
String
privateKey
=
encodeBase64
(
keyBs
);
String
privateKey
=
encodeBase64
(
keyBs
);
logger
.
info
(
"生成的私钥:\t{}
"
,
privateKey
);
Log
.
info
(
RsaHelper
.
class
,
"生成的私钥:\t %s
"
,
privateKey
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
}
}
...
@@ -204,9 +200,9 @@ public final class RsaHelper {
...
@@ -204,9 +200,9 @@ public final class RsaHelper {
signature
.
initVerify
(
publicKey
);
signature
.
initVerify
(
publicKey
);
signature
.
update
(
target
.
getBytes
(
SystemContants
.
UTF8
));
signature
.
update
(
target
.
getBytes
(
SystemContants
.
UTF8
));
if
(
signature
.
verify
(
decodeBase64
(
sign
)))
{
if
(
signature
.
verify
(
decodeBase64
(
sign
)))
{
logger
.
info
(
"sign true"
);
Log
.
info
(
RsaHelper
.
class
,
"sign true"
);
}
else
{
}
else
{
logger
.
info
(
"sign false"
);
Log
.
info
(
RsaHelper
.
class
,
"sign false"
);
}
}
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
...
@@ -265,7 +261,7 @@ public final class RsaHelper {
...
@@ -265,7 +261,7 @@ public final class RsaHelper {
return
new
String
(
to
,
SystemContants
.
UTF8
);
return
new
String
(
to
,
SystemContants
.
UTF8
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
throw
YzgError
.
getRuntimeException
(
ex
,
"056"
,
ex
.
getMessage
());
throw
YzgError
.
getRuntimeException
(
ex
,
"056"
,
ex
.
getMessage
());
}
}
}
}
...
...
yzg-util-base/src/test/java/helper/TestRsa.java
View file @
95d7f2f4
...
@@ -17,7 +17,7 @@ public class TestRsa {
...
@@ -17,7 +17,7 @@ public class TestRsa {
String
privateKey
=
"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALcZ2sh1PaU5uVJqVeDDgGOe/t/bJsf6K/f1AtQ7iPU943S9pyzBCCZSrcoctvFZ4Go1N2y5H8bnMq/h7etoRiwDGuUfD8AkIlA4pOlgQ8ouJWE2PuaqDX4jroFHBob0C6c3hsXot9OPbCAUSVVsUZu/W/xIRUNFiJSTBWwCjkmpAgMBAAECgYBwJ18SsHWtEhmI+OdXgIjQ/J/j4Kn1jjCGdkZgV4NBrMH5TP3sdOSYDMa06TfJyCKlC6nCZ/al8BHlF/+S1VE9Mu8DRrbHAO4OJQyOEaQ64mePL6jYkhVbjr4q7kHTbsIWVu3sH9TJRa3n+lsEpEv90ri458+ofn++h+rlYKlLfQJBAPVWi1VanQlyAtGKmeA7GrxH+XYiqeq4J1suT1qUTsRwEM4RLUZcrsdGio2bVwbbyX3TB2vYdLvf1otdndKBr0MCQQC/Due/BN+B/hqOgMdW2RoHfycg/HVOp7CpsBikRUMegDQGPb6N+z/BIXkVBNHBADzaTcJh0DgSsoMRhlEdTWajAkEAq2V31/yDAytEbtGOqMmB5xG9ZNvYq2NWE2xqAdTkpnXIN75mS+bKL+vHNiD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
;
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
50
0
;
i
++)
{
for
(
int
i
=
0
;
i
<
50
;
i
++)
{
sb
.
append
((
char
)
(
'A'
+
i
%
26
));
sb
.
append
((
char
)
(
'A'
+
i
%
26
));
}
}
String
from
=
sb
.
toString
();
String
from
=
sb
.
toString
();
...
...
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