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
47202569
Commit
47202569
authored
Jul 13, 2022
by
yangyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
海南加密解密处理
parent
ec3f3d9e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
common/common_utils/src/main/java/com/founder/commonutils/util/AesEncryptUtil.java
+19
-6
No files found.
common/common_utils/src/main/java/com/founder/commonutils/util/AesEncryptUtil.java
View file @
47202569
...
@@ -5,8 +5,11 @@ import org.apache.commons.codec.binary.Base64;
...
@@ -5,8 +5,11 @@ import org.apache.commons.codec.binary.Base64;
import
javax.crypto.Cipher
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
javax.servlet.http.HttpServletResponse
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* AES 128bit 加密解密工具类
* AES 128bit 加密解密工具类
...
@@ -34,7 +37,8 @@ public class AesEncryptUtil {
...
@@ -34,7 +37,8 @@ public class AesEncryptUtil {
*/
*/
public
static
String
encrypt
(
String
data
,
String
key
,
String
iv
)
throws
Exception
{
public
static
String
encrypt
(
String
data
,
String
key
,
String
iv
)
throws
Exception
{
try
{
try
{
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/PKCS5Padding"
);
//"算法/模式/补码方式"NoPadding PkcsPadding
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/NoPadding"
);
//"算法/模式/补码方式"NoPadding PkcsPadding
int
blockSize
=
cipher
.
getBlockSize
();
int
blockSize
=
cipher
.
getBlockSize
();
byte
[]
dataBytes
=
data
.
getBytes
();
byte
[]
dataBytes
=
data
.
getBytes
();
...
@@ -72,8 +76,7 @@ public class AesEncryptUtil {
...
@@ -72,8 +76,7 @@ public class AesEncryptUtil {
try
{
try
{
data
=
data
.
replaceAll
(
" "
,
"+"
);
data
=
data
.
replaceAll
(
" "
,
"+"
);
byte
[]
encrypted1
=
new
Base64
().
decode
(
data
);
byte
[]
encrypted1
=
new
Base64
().
decode
(
data
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/NoPadding"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/PKCS5Padding"
);
SecretKeySpec
keyspec
=
new
SecretKeySpec
(
key
.
getBytes
(),
"AES"
);
SecretKeySpec
keyspec
=
new
SecretKeySpec
(
key
.
getBytes
(),
"AES"
);
IvParameterSpec
ivspec
=
new
IvParameterSpec
(
iv
.
getBytes
());
IvParameterSpec
ivspec
=
new
IvParameterSpec
(
iv
.
getBytes
());
...
@@ -84,7 +87,7 @@ public class AesEncryptUtil {
...
@@ -84,7 +87,7 @@ public class AesEncryptUtil {
return
originalString
;
return
originalString
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
"解密失败"
;
}
}
}
}
...
@@ -110,22 +113,31 @@ public class AesEncryptUtil {
...
@@ -110,22 +113,31 @@ public class AesEncryptUtil {
return
desEncrypt
(
data
,
KEY
,
IV
);
return
desEncrypt
(
data
,
KEY
,
IV
);
}
}
public
static
Map
<
String
,
Object
>
getMap
(
Integer
status
,
String
msg
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"code"
,
status
);
map
.
put
(
"msg"
,
msg
);
return
map
;
}
/**
/**
* 测试
* 测试
*/
*/
public
static
void
main
(
String
args
[])
throws
Exception
{
public
static
void
main
(
String
args
[])
throws
Exception
{
String
test1
=
"4
6
0000000000000000"
;
String
test1
=
"4
3
0000000000000000"
;
String
test
=
new
String
(
test1
.
getBytes
(),
"UTF-8"
);
String
test
=
new
String
(
test1
.
getBytes
(),
"UTF-8"
);
String
data
=
null
;
String
data
=
null
;
String
key
=
KEY
;
String
key
=
KEY
;
String
iv
=
IV
;
String
iv
=
IV
;
// /g2wzfqvMOeazgtsUVbq1kmJawROa6mcRAzwG1/GeJ4=
data
=
encrypt
(
test
,
key
,
iv
);
data
=
encrypt
(
test
,
key
,
iv
);
System
.
out
.
println
(
"数据:"
+
test
);
System
.
out
.
println
(
"数据:"
+
test
);
System
.
out
.
println
(
"加密:"
+
data
);
System
.
out
.
println
(
"加密:"
+
data
);
String
jiemi
=
desEncrypt
(
data
,
key
,
iv
).
trim
();
String
jiemi
=
desEncrypt
(
data
,
key
,
iv
).
trim
();
System
.
out
.
println
(
"解密:"
+
jiemi
);
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