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
02ebe5c3
Commit
02ebe5c3
authored
Nov 18, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实体位置
parent
3d1b7b04
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
RsaHelper.java
.../src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
+11
-3
TestRsa.java
yzg-util-base/src/test/java/helper/TestRsa.java
+1
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
View file @
02ebe5c3
...
...
@@ -28,7 +28,15 @@ public final class RsaHelper {
private
static
final
String
ALGORITHM_SIGN
=
"MD5withRSA"
;
private
static
final
int
KEYPAIR_LEN
=
1024
;
public
static
final
int
MAX_ENCRYPT_BLOCK
=
64
;
/**
* RSA最大加密明文大小
*/
private
static
final
int
MAX_ENCRYPT_BLOCK
=
117
;
/**
* RSA最大解密密文大小
*/
private
static
final
int
MAX_DECRYPT_BLOCK
=
128
;
private
RsaHelper
()
{
super
();
...
...
@@ -156,7 +164,7 @@ public final class RsaHelper {
Cipher
cipher
=
Cipher
.
getInstance
(
publicKey
.
getAlgorithm
());
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
publicKey
);
byte
[]
to
=
handle
(
bytes
,
MAX_
EN
CRYPT_BLOCK
,
new
HandleBytes
()
{
byte
[]
to
=
handle
(
bytes
,
MAX_
DE
CRYPT_BLOCK
,
new
HandleBytes
()
{
@Override
public
byte
[]
handle
(
byte
[]
from
,
int
offset
,
int
len
)
throws
Exception
{
return
cipher
.
doFinal
(
from
,
offset
,
len
);
...
...
@@ -234,7 +242,7 @@ public final class RsaHelper {
Cipher
cipher
=
Cipher
.
getInstance
(
privateKey
.
getAlgorithm
());
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
privateKey
);
byte
[]
to
=
handle
(
bytes
,
MAX_
EN
CRYPT_BLOCK
,
new
HandleBytes
()
{
byte
[]
to
=
handle
(
bytes
,
MAX_
DE
CRYPT_BLOCK
,
new
HandleBytes
()
{
@Override
public
byte
[]
handle
(
byte
[]
from
,
int
offset
,
int
len
)
throws
Exception
{
return
cipher
.
doFinal
(
from
,
offset
,
len
);
...
...
yzg-util-base/src/test/java/helper/TestRsa.java
View file @
02ebe5c3
...
...
@@ -21,6 +21,7 @@ public class TestRsa {
sb
.
append
((
char
)
(
'A'
+
i
%
26
));
}
String
from
=
sb
.
toString
();
String
value
=
RsaHelper
.
encryptionByPublicKey
(
from
,
publicKey
);
String
result
=
RsaHelper
.
decryptionByPrivateKey
(
value
,
privateKey
);
System
.
out
.
println
(
from
);
...
...
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