Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
5f7fb708
Commit
5f7fb708
authored
Mar 28, 2022
by
郑勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: [1006875] 【新增】ERP账号申领
parent
332255a2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
0 deletions
+77
-0
AESUtil.java
...rc/main/java/com/pcloud/common/utils/encrypt/AESUtil.java
+77
-0
No files found.
pcloud-common/src/main/java/com/pcloud/common/utils/encrypt/AESUtil.java
View file @
5f7fb708
...
@@ -140,4 +140,81 @@ public class AESUtil {
...
@@ -140,4 +140,81 @@ public class AESUtil {
}
}
return
hs
.
toString
().
toUpperCase
();
return
hs
.
toString
().
toUpperCase
();
}
}
/**
* 使用固定密钥加密
* @param src 待加密数据
* @return 加密后数据
*/
public
static
String
fixedEncrypt
(
final
String
src
,
String
key
)
{
if
(
StringUtils
.
isBlank
(
src
))
{
return
src
;
}
if
(
StringUtils
.
isBlank
(
key
))
{
key
=
DEFAULT_KEY
;
}
try
{
byte
[]
encrypted
=
getEncryptCipherInstance
(
key
).
doFinal
(
src
.
getBytes
());
return
byte2hex
(
encrypted
);
}
catch
(
Throwable
t
)
{
throw
new
BizException
(
"aes encrypt failed,src="
+
src
,
t
);
}
}
private
static
Cipher
getEncryptCipherInstance
(
String
key
)
{
if
(
ENCRYPT_CIPHER
==
null
)
{
synchronized
(
AESUtil
.
class
)
{
if
(
ENCRYPT_CIPHER
==
null
)
{
try
{
byte
[]
raw
=
key
.
getBytes
();
SecretKeySpec
spec
=
new
SecretKeySpec
(
raw
,
KEY_AES
);
ENCRYPT_CIPHER
=
Cipher
.
getInstance
(
KEY_AES
);
ENCRYPT_CIPHER
.
init
(
Cipher
.
ENCRYPT_MODE
,
spec
);
}
catch
(
Throwable
t
)
{
ENCRYPT_CIPHER
=
null
;
throw
new
BizException
(
"aes cipher init failed"
,
t
);
}
}
}
}
return
ENCRYPT_CIPHER
;
}
public
static
String
fixedDecrypt
(
final
String
encrypted
,
String
key
)
{
if
(
StringUtils
.
isBlank
(
encrypted
))
{
return
encrypted
;
}
if
(
StringUtils
.
isBlank
(
key
))
{
key
=
DEFAULT_KEY
;
}
try
{
byte
[]
b
=
hex2byte
(
encrypted
);
if
(
b
==
null
)
{
throw
new
BizException
(
"aes decrypt failed,src="
+
encrypted
);
}
byte
[]
original
=
getDecryptCipherInstance
(
key
).
doFinal
(
b
);
return
new
String
(
original
,
StandardCharsets
.
UTF_8
);
}
catch
(
Throwable
t
)
{
throw
new
BizException
(
"aes decrypt failed,src="
+
encrypted
,
t
);
}
}
private
static
Cipher
getDecryptCipherInstance
(
String
key
)
{
if
(
DECRYPT_CIPHER
==
null
)
{
synchronized
(
AESUtil
.
class
)
{
if
(
DECRYPT_CIPHER
==
null
)
{
try
{
byte
[]
raw
=
key
.
getBytes
();
SecretKeySpec
spec
=
new
SecretKeySpec
(
raw
,
KEY_AES
);
DECRYPT_CIPHER
=
Cipher
.
getInstance
(
KEY_AES
);
DECRYPT_CIPHER
.
init
(
Cipher
.
DECRYPT_MODE
,
spec
);
}
catch
(
Throwable
t
)
{
DECRYPT_CIPHER
=
null
;
throw
new
BizException
(
"aes cipher init failed"
,
t
);
}
}
}
}
return
DECRYPT_CIPHER
;
}
}
}
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