Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-notice
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-notice
Commits
0868fc62
Commit
0868fc62
authored
Apr 03, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
156bacf5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
46 deletions
+54
-46
.idea/ProjectStorage.xml
+8
-0
yd-notice-service/src/main/java/com/yd/notice/service/utils/AesEncryptUtil.java
+46
-46
No files found.
.idea/ProjectStorage.xml
0 → 100644
View file @
0868fc62
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectStorage"
>
<option
name=
"path"
value=
"项目群组->银盾-微服务"
/>
<option
name=
"projectId"
value=
"4cc05386e898000"
/>
</component>
</project>
\ No newline at end of file
yd-notice-service/src/main/java/com/yd/notice/service/utils/AesEncryptUtil.java
View file @
0868fc62
package
com
.
yd
.
notice
.
service
.
utils
;
//package com.yd.notice.service.utils;
//
import
lombok.extern.slf4j.Slf4j
;
//import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Value
;
//import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Component
;
//import org.springframework.stereotype.Component;
import
javax.crypto.Cipher
;
//import javax.crypto.Cipher;
import
javax.crypto.spec.SecretKeySpec
;
//import javax.crypto.spec.SecretKeySpec;
import
java.util.Base64
;
//import java.util.Base64;
//
@Slf4j
//@Slf4j
@Component
//@Component
public
class
AesEncryptUtil
{
//public class AesEncryptUtil {
private
static
final
String
ALGORITHM
=
"AES"
;
// private static final String ALGORITHM = "AES";
private
static
final
String
TRANSFORMATION
=
"AES/ECB/PKCS5Padding"
;
// private static final String TRANSFORMATION = "AES/ECB/PKCS5Padding";
//
@Value
(
"${notice.aes.secret-key}"
)
// @Value("${notice.aes.secret-key}")
private
String
secretKey
;
// 从配置文件注入,建议使用16/24/32字节的密钥
// private String secretKey; // 从配置文件注入,建议使用16/24/32字节的密钥
//
public
String
encrypt
(
String
plainText
)
{
// public String encrypt(String plainText) {
try
{
// try {
SecretKeySpec
keySpec
=
new
SecretKeySpec
(
secretKey
.
getBytes
(),
ALGORITHM
);
// SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), ALGORITHM);
Cipher
cipher
=
Cipher
.
getInstance
(
TRANSFORMATION
);
// Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
keySpec
);
// cipher.init(Cipher.ENCRYPT_MODE, keySpec);
byte
[]
encrypted
=
cipher
.
doFinal
(
plainText
.
getBytes
());
// byte[] encrypted = cipher.doFinal(plainText.getBytes());
return
Base64
.
getEncoder
().
encodeToString
(
encrypted
);
// return Base64.getEncoder().encodeToString(encrypted);
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
log
.
error
(
"加密失败"
,
e
);
// log.error("加密失败", e);
throw
new
RuntimeException
(
"加密失败"
,
e
);
// throw new RuntimeException("加密失败", e);
}
// }
}
// }
//
public
String
decrypt
(
String
cipherText
)
{
// public String decrypt(String cipherText) {
try
{
// try {
SecretKeySpec
keySpec
=
new
SecretKeySpec
(
secretKey
.
getBytes
(),
ALGORITHM
);
// SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), ALGORITHM);
Cipher
cipher
=
Cipher
.
getInstance
(
TRANSFORMATION
);
// Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
keySpec
);
// cipher.init(Cipher.DECRYPT_MODE, keySpec);
byte
[]
decoded
=
Base64
.
getDecoder
().
decode
(
cipherText
);
// byte[] decoded = Base64.getDecoder().decode(cipherText);
byte
[]
decrypted
=
cipher
.
doFinal
(
decoded
);
// byte[] decrypted = cipher.doFinal(decoded);
return
new
String
(
decrypted
);
// return new String(decrypted);
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
log
.
error
(
"解密失败"
,
e
);
// log.error("解密失败", e);
throw
new
RuntimeException
(
"解密失败"
,
e
);
// throw new RuntimeException("解密失败", e);
}
// }
}
// }
}
//}
\ No newline at end of file
\ No newline at end of file
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