Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
map-parent
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
常超
map-parent
Commits
4ee35eb2
Commit
4ee35eb2
authored
Jul 13, 2022
by
yangyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
海南单点登录
parent
c0007805
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
common/common_utils/src/main/java/com/founder/commonutils/util/AesEncryptUtil.java
+12
-12
No files found.
common/common_utils/src/main/java/com/founder/commonutils/util/AesEncryptUtil.java
View file @
4ee35eb2
...
...
@@ -5,6 +5,8 @@ import org.apache.commons.codec.binary.Base64;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
/**
* AES 128bit 加密解密工具类
...
...
@@ -14,11 +16,12 @@ import javax.crypto.spec.SecretKeySpec;
public
class
AesEncryptUtil
{
private
static
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
private
static
String
today
=
simpleDateFormat
.
format
(
new
Date
());
//使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同!
private
static
String
KEY
=
"maplogin
20200416"
;
private
static
String
KEY
=
"maplogin
"
+
today
;
private
static
String
IV
=
"map_vues
20200416"
;
private
static
String
IV
=
"map_vues
"
+
today
;
/**
...
...
@@ -31,8 +34,7 @@ public class AesEncryptUtil {
*/
public
static
String
encrypt
(
String
data
,
String
key
,
String
iv
)
throws
Exception
{
try
{
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/NoPadding"
);
//"算法/模式/补码方式"NoPadding PkcsPadding
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/PKCS5Padding"
);
//"算法/模式/补码方式"NoPadding PkcsPadding
int
blockSize
=
cipher
.
getBlockSize
();
byte
[]
dataBytes
=
data
.
getBytes
();
...
...
@@ -68,9 +70,10 @@ public class AesEncryptUtil {
*/
public
static
String
desEncrypt
(
String
data
,
String
key
,
String
iv
)
throws
Exception
{
try
{
data
=
data
.
replaceAll
(
" "
,
"+"
);
byte
[]
encrypted1
=
new
Base64
().
decode
(
data
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/
No
Padding"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/
PKCS5
Padding"
);
SecretKeySpec
keyspec
=
new
SecretKeySpec
(
key
.
getBytes
(),
"AES"
);
IvParameterSpec
ivspec
=
new
IvParameterSpec
(
iv
.
getBytes
());
...
...
@@ -85,6 +88,8 @@ public class AesEncryptUtil {
}
}
/**
* 使用默认的key和iv加密
* @param data
...
...
@@ -112,19 +117,15 @@ public class AesEncryptUtil {
*/
public
static
void
main
(
String
args
[])
throws
Exception
{
String
test1
=
"1
111111111
000000"
;
String
test1
=
"1
50000000000
000000"
;
String
test
=
new
String
(
test1
.
getBytes
(),
"UTF-8"
);
String
data
=
null
;
String
key
=
KEY
;
String
iv
=
IV
;
// /g2wzfqvMOeazgtsUVbq1kmJawROa6mcRAzwG1/GeJ4=
data
=
encrypt
(
test
,
key
,
iv
);
System
.
out
.
println
(
"数据:"
+
test
);
System
.
out
.
println
(
"加密:"
+
data
);
String
jiemi
=
desEncrypt
(
data
,
key
,
iv
).
trim
();
System
.
out
.
println
(
"解密:"
+
jiemi
);
}
}
\ 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