Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
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
head_group
xyqb-user2
Commits
2736f9ca
Commit
2736f9ca
authored
Oct 30, 2019
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RSA
parent
1d7c4cb4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
Rsa.java
src/main/java/cn/quantgroup/xyqb/util/encrypt/Rsa.java
+6
-6
No files found.
src/main/java/cn/quantgroup/xyqb/util/encrypt/Rsa.java
View file @
2736f9ca
...
@@ -20,7 +20,7 @@ public class Rsa {
...
@@ -20,7 +20,7 @@ public class Rsa {
private
static
int
KEYSIZE
=
1024
;
private
static
int
KEYSIZE
=
1024
;
public
static
final
String
CHAR_ENCODING
=
"UTF-8"
;
public
static
final
String
CHAR_ENCODING
=
"UTF-8"
;
public
static
final
String
RSA_ALGORITHM
=
"R
sa
/ECB/PKCS1Padding"
;
public
static
final
String
RSA_ALGORITHM
=
"R
SA
/ECB/PKCS1Padding"
;
/** */
/** */
/**
/**
...
@@ -41,7 +41,7 @@ public class Rsa {
...
@@ -41,7 +41,7 @@ public class Rsa {
/** RSA算法要求有一个可信任的随机数源 */
/** RSA算法要求有一个可信任的随机数源 */
SecureRandom
sr
=
new
SecureRandom
();
SecureRandom
sr
=
new
SecureRandom
();
/** 为RSA算法创建一个KeyPairGenerator对象 */
/** 为RSA算法创建一个KeyPairGenerator对象 */
KeyPairGenerator
kpg
=
KeyPairGenerator
.
getInstance
(
"R
sa
"
);
KeyPairGenerator
kpg
=
KeyPairGenerator
.
getInstance
(
"R
SA
"
);
/** 利用上面的随机数据源初始化这个KeyPairGenerator对象 */
/** 利用上面的随机数据源初始化这个KeyPairGenerator对象 */
kpg
.
initialize
(
KEYSIZE
,
sr
);
kpg
.
initialize
(
KEYSIZE
,
sr
);
/** 生成密匙对 */
/** 生成密匙对 */
...
@@ -143,7 +143,7 @@ public class Rsa {
...
@@ -143,7 +143,7 @@ public class Rsa {
public
static
PublicKey
getPublicKey
(
String
key
)
throws
Exception
{
public
static
PublicKey
getPublicKey
(
String
key
)
throws
Exception
{
X509EncodedKeySpec
keySpec
=
new
X509EncodedKeySpec
(
X509EncodedKeySpec
keySpec
=
new
X509EncodedKeySpec
(
Base64
.
decodeBase64
(
key
.
getBytes
()));
Base64
.
decodeBase64
(
key
.
getBytes
()));
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"R
sa
"
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"R
SA
"
);
PublicKey
publicKey
=
keyFactory
.
generatePublic
(
keySpec
);
PublicKey
publicKey
=
keyFactory
.
generatePublic
(
keySpec
);
return
publicKey
;
return
publicKey
;
}
}
...
@@ -157,7 +157,7 @@ public class Rsa {
...
@@ -157,7 +157,7 @@ public class Rsa {
public
static
PrivateKey
getPrivateKey
(
String
key
)
throws
Exception
{
public
static
PrivateKey
getPrivateKey
(
String
key
)
throws
Exception
{
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
Base64
.
decodeBase64
(
key
.
getBytes
()));
Base64
.
decodeBase64
(
key
.
getBytes
()));
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"R
sa
"
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"R
SA
"
);
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
return
privateKey
;
return
privateKey
;
}
}
...
@@ -167,7 +167,7 @@ public class Rsa {
...
@@ -167,7 +167,7 @@ public class Rsa {
try
{
try
{
PKCS8EncodedKeySpec
priPKCS8
=
new
PKCS8EncodedKeySpec
(
PKCS8EncodedKeySpec
priPKCS8
=
new
PKCS8EncodedKeySpec
(
Base64
.
decodeBase64
(
privateKey
.
getBytes
()));
Base64
.
decodeBase64
(
privateKey
.
getBytes
()));
KeyFactory
keyf
=
KeyFactory
.
getInstance
(
"R
sa
"
);
KeyFactory
keyf
=
KeyFactory
.
getInstance
(
"R
SA
"
);
PrivateKey
priKey
=
keyf
.
generatePrivate
(
priPKCS8
);
PrivateKey
priKey
=
keyf
.
generatePrivate
(
priPKCS8
);
Signature
signature
=
Signature
.
getInstance
(
"SHA1WithRSA"
);
Signature
signature
=
Signature
.
getInstance
(
"SHA1WithRSA"
);
signature
.
initSign
(
priKey
);
signature
.
initSign
(
priKey
);
...
@@ -182,7 +182,7 @@ public class Rsa {
...
@@ -182,7 +182,7 @@ public class Rsa {
public
static
boolean
checkSign
(
String
content
,
String
sign
,
String
publicKey
)
{
public
static
boolean
checkSign
(
String
content
,
String
sign
,
String
publicKey
)
{
try
{
try
{
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"R
sa
"
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"R
SA
"
);
byte
[]
encodedKey
=
Base64
.
decode2
(
publicKey
);
byte
[]
encodedKey
=
Base64
.
decode2
(
publicKey
);
PublicKey
pubKey
=
keyFactory
.
generatePublic
(
new
X509EncodedKeySpec
(
encodedKey
));
PublicKey
pubKey
=
keyFactory
.
generatePublic
(
new
X509EncodedKeySpec
(
encodedKey
));
Signature
signature
=
Signature
.
getInstance
(
"SHA1WithRSA"
);
Signature
signature
=
Signature
.
getInstance
(
"SHA1WithRSA"
);
...
...
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