Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiwei-api
Project
Project
Details
Activity
Releases
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
马天浩
jiwei-api
Commits
dcfb0ed0
Commit
dcfb0ed0
authored
Dec 02, 2020
by
matianhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[资产资源接口] <add> DES解密
parent
7fe79a6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
AESUtils.java
src/main/java/com/mth/requestsecret/util/AESUtils.java
+54
-0
No files found.
src/main/java/com/mth/requestsecret/util/AESUtils.java
View file @
dcfb0ed0
...
...
@@ -5,9 +5,12 @@ import org.apache.commons.lang.StringUtils;
import
org.bouncycastle.jce.provider.BouncyCastleProvider
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKeyFactory
;
import
javax.crypto.spec.DESedeKeySpec
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.StandardCharsets
;
import
java.security.Key
;
import
java.security.Security
;
import
java.util.Base64
;
...
...
@@ -129,4 +132,55 @@ public class AESUtils {
}
}
/**
* 16进制字符串转字节数组
*
* @param hexStr
* @return
*/
public
static
byte
[]
hexStr2Byte
(
String
hexStr
)
{
String
str
=
"0123456789ABCDEF"
;
char
[]
hexs
=
hexStr
.
toCharArray
();
byte
[]
bytes
=
new
byte
[
hexStr
.
length
()
/
2
];
int
n
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
n
=
str
.
indexOf
(
hexs
[
2
*
i
])
*
16
;
n
+=
str
.
indexOf
(
hexs
[
2
*
i
+
1
]);
bytes
[
i
]
=
(
byte
)
(
n
&
0xff
);
}
return
bytes
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// 秘钥
String
key
=
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4"
;
// 待解密参数
String
content
=
"6B2E012D451E446DA87BED8BB65F23879D27E80BAE10980BBC79BA0EC894392C7CC82E659370A366"
;
try
{
// 算法/模式/补码方式
Cipher
cipher
=
Cipher
.
getInstance
(
"desede/ECB/NoPadding"
);
// key
DESedeKeySpec
keySpec
=
new
DESedeKeySpec
(
Base64
.
getDecoder
().
decode
(
key
));
//获取DES秘钥生成器对象
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
"desede"
);
// 生成秘钥:key的长度不能够小于8位字节
Key
secretKey
=
keyFactory
.
generateSecret
(
keySpec
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
secretKey
);
byte
[]
origin
=
cipher
.
doFinal
(
hexStr2Byte
(
content
));
System
.
out
.
println
(
new
String
(
origin
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
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