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
ce4c8090
Commit
ce4c8090
authored
Dec 07, 2022
by
王亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add crypt converter.
parent
b69bf223
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
AESUtils.java
src/main/java/cn/quantgroup/xyqb/util/AESUtils.java
+45
-0
CryptConverter.java
.../java/cn/quantgroup/xyqb/util/encrypt/CryptConverter.java
+17
-0
No files found.
src/main/java/cn/quantgroup/xyqb/util/AESUtils.java
0 → 100644
View file @
ce4c8090
package
cn
.
quantgroup
.
xyqb
.
util
;
import
cn.quantgroup.security.AESEncryption
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigService
;
import
org.apache.commons.lang3.StringUtils
;
public
class
AESUtils
{
public
static
AESEncryption
encryption
;
/**
* V2方法不再考虑历史数据兼容问题
*
* @param plainValue 明文
* @return 密文
*/
public
static
String
encryptV2
(
final
String
plainValue
)
{
if
(
StringUtils
.
isNotEmpty
(
plainValue
))
{
return
encryption
().
encryptBase64
(
plainValue
);
}
return
plainValue
;
}
/**
* V2方法不再考虑历史数据兼容问题
*
* @param cipherValue 明文
* @return 密文
*/
public
static
String
decryptV2
(
String
cipherValue
)
{
return
StringUtils
.
isNotEmpty
(
cipherValue
)
?
encryption
().
decryptBase64
(
cipherValue
)
:
cipherValue
;
}
public
static
AESEncryption
encryption
()
{
if
(
encryption
==
null
)
{
Config
config
=
ConfigService
.
getAppConfig
();
String
key
=
config
.
getProperty
(
"encrypt.key"
,
""
);
String
iv
=
config
.
getProperty
(
"encrypt.iv"
,
""
);
encryption
=
new
AESEncryption
(
key
,
iv
,
true
);
}
return
encryption
;
}
}
src/main/java/cn/quantgroup/xyqb/util/encrypt/CryptConverter.java
0 → 100644
View file @
ce4c8090
package
cn
.
quantgroup
.
xyqb
.
util
.
encrypt
;
import
cn.quantgroup.xyqb.util.AESUtils
;
import
javax.persistence.AttributeConverter
;
public
class
CryptConverter
implements
AttributeConverter
<
String
,
String
>
{
@Override
public
String
convertToDatabaseColumn
(
String
attribute
)
{
return
AESUtils
.
encryptV2
(
attribute
);
}
@Override
public
String
convertToEntityAttribute
(
String
dbData
)
{
return
AESUtils
.
decryptV2
(
dbData
);
}
}
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