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
a55e27c4
Commit
a55e27c4
authored
Jan 11, 2025
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加密优化
parent
54656191
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
src/main/java/com/zksy/szpt/util/EncryptUtil.java
src/main/java/com/zksy/szpt/util/EncryptUtil.java
+24
-2
src/main/java/com/zksy/szpt/util/SignatureUtil.java
src/main/java/com/zksy/szpt/util/SignatureUtil.java
+1
-1
No files found.
src/main/java/com/zksy/szpt/util/EncryptUtil.java
View file @
a55e27c4
...
...
@@ -5,6 +5,7 @@ import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import
javax.crypto.Cipher
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.StandardCharsets
;
import
java.security.MessageDigest
;
...
...
@@ -138,10 +139,31 @@ public class EncryptUtil {
/**
* 使用AES加密算法经行加密(可逆)
*
* @param res 需要加密的密文
* @param data 需要加密的密文
* @param password 秘钥
*/
public
String
AESEncode
(
String
data
,
String
password
)
{
byte
[]
key
=
password
.
getBytes
();
//16字节密钥
byte
[]
iv
=
"1234567890123456"
.
getBytes
();
//iv
SecretKey
secretKey
=
new
SecretKeySpec
(
key
,
"AES"
);
try
{
IvParameterSpec
ivSpec
=
new
IvParameterSpec
(
iv
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/PKCS5Padding"
);
//加密算法/模式/填充方式
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
secretKey
,
ivSpec
);
byte
[]
encrypted
=
cipher
.
doFinal
(
data
.
getBytes
());
//密文字节数组
return
Base64
.
encode
(
encrypted
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 使用AES加密算法经行加密(可逆)
*
* @param res 需要加密的密文
* @param key 秘钥
*/
public
String
AESEncode
(
String
res
,
String
key
)
{
public
String
AESEncode
1
(
String
res
,
String
key
)
{
return
keyGeneratorES
(
res
,
AES
,
key
,
keySizeAES
,
true
);
}
...
...
src/main/java/com/zksy/szpt/util/SignatureUtil.java
View file @
a55e27c4
...
...
@@ -5,5 +5,5 @@ public class SignatureUtil {
public
static
String
TIMESTAMP
=
"x-szpt-timestamp"
;
public
static
String
NONCE
=
"x-szpt-nonce"
;
public
static
String
APPID
=
"x-szpt-appid"
;
public
static
String
DEPT_CODE
=
"x-szpt-dept
_
code"
;
public
static
String
DEPT_CODE
=
"x-szpt-dept
-
code"
;
}
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