Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
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
黄营
datax-cloud
Commits
f31d29a2
Commit
f31d29a2
authored
Dec 11, 2020
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update: MD5加密密钥修改
parent
2a173a02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
12 deletions
+22
-12
MD5Util.java
...mon-core/src/main/java/cn/datax/common/utils/MD5Util.java
+22
-12
No files found.
datax-common/datax-common-core/src/main/java/cn/datax/common/utils/MD5Util.java
View file @
f31d29a2
...
@@ -12,10 +12,12 @@ import java.util.Base64;
...
@@ -12,10 +12,12 @@ import java.util.Base64;
public
class
MD5Util
{
public
class
MD5Util
{
//向量(同时拥有向量和密匙才能解密),此向量必须是8byte,多少都报错
/** 向量(同时拥有向量和密匙才能解密),此向量必须是8byte,多少都报错 */
private
final
byte
[]
DESIV
=
new
byte
[]
{
0x22
,
0x54
,
0x36
,
110
,
0x40
,
(
byte
)
0xac
,
(
byte
)
0xad
,
(
byte
)
0xdf
};
// 向量
private
final
byte
[]
DESIV
=
new
byte
[]
{
0x22
,
0x54
,
0x36
,
110
,
0x40
,
(
byte
)
0xac
,
(
byte
)
0xad
,
(
byte
)
0xdf
};
private
final
String
deSkey
=
"datax-cloud"
;
// 自定义密钥,个数不能太短,太短报错,过长,它默认只取前N位(N的具体值,大家另行查找资料)
/** 自定义密钥,个数不能太短,太短报错,过长,它默认只取前N位(N的具体值,大家另行查找资料) */
private
AlgorithmParameterSpec
iv
=
null
;
// 加密算法的参数接口
private
final
String
deSkey
=
"datax-cloud"
;
/** 加密算法的参数接口 */
private
AlgorithmParameterSpec
iv
=
null
;
private
Key
key
=
null
;
private
Key
key
=
null
;
private
String
charset
=
"UTF-8"
;
private
String
charset
=
"UTF-8"
;
...
@@ -26,10 +28,14 @@ public class MD5Util {
...
@@ -26,10 +28,14 @@ public class MD5Util {
* @throws Exception
* @throws Exception
*/
*/
private
MD5Util
()
throws
Exception
{
private
MD5Util
()
throws
Exception
{
DESKeySpec
keySpec
=
new
DESKeySpec
(
deSkey
.
getBytes
(
this
.
charset
));
// 设置密钥参数
// 设置密钥参数
iv
=
new
IvParameterSpec
(
DESIV
);
// 设置向量
DESKeySpec
keySpec
=
new
DESKeySpec
(
deSkey
.
getBytes
(
this
.
charset
));
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
"DES"
);
// 获得密钥工厂
// 设置向量
key
=
keyFactory
.
generateSecret
(
keySpec
);
// 得到密钥对象
iv
=
new
IvParameterSpec
(
DESIV
);
// 获得密钥工厂
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
"DES"
);
// 得到密钥对象
key
=
keyFactory
.
generateSecret
(
keySpec
);
}
}
public
static
MD5Util
getInstance
()
throws
Exception
{
public
static
MD5Util
getInstance
()
throws
Exception
{
...
@@ -63,8 +69,10 @@ public class MD5Util {
...
@@ -63,8 +69,10 @@ public class MD5Util {
* @throws Exception
* @throws Exception
*/
*/
public
String
encode
(
String
data
)
throws
Exception
{
public
String
encode
(
String
data
)
throws
Exception
{
Cipher
enCipher
=
Cipher
.
getInstance
(
"DES/CBC/PKCS5Padding"
);
// 得到加密对象Cipher
// 得到加密对象Cipher
enCipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
key
,
iv
);
// 设置工作模式为加密模式,给出密钥和向量
Cipher
enCipher
=
Cipher
.
getInstance
(
"DES/CBC/PKCS5Padding"
);
// 设置工作模式为加密模式,给出密钥和向量
enCipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
key
,
iv
);
byte
[]
pasByte
=
enCipher
.
doFinal
(
data
.
getBytes
(
this
.
charset
));
byte
[]
pasByte
=
enCipher
.
doFinal
(
data
.
getBytes
(
this
.
charset
));
return
Base64
.
getEncoder
().
encodeToString
(
pasByte
);
return
Base64
.
getEncoder
().
encodeToString
(
pasByte
);
}
}
...
@@ -99,10 +107,12 @@ public class MD5Util {
...
@@ -99,10 +107,12 @@ public class MD5Util {
StringBuffer
buf
=
new
StringBuffer
(
""
);
StringBuffer
buf
=
new
StringBuffer
(
""
);
for
(
int
offset
=
0
;
offset
<
b
.
length
;
offset
++)
{
for
(
int
offset
=
0
;
offset
<
b
.
length
;
offset
++)
{
i
=
b
[
offset
];
i
=
b
[
offset
];
if
(
i
<
0
)
if
(
i
<
0
)
{
i
+=
256
;
i
+=
256
;
if
(
i
<
16
)
}
if
(
i
<
16
)
{
buf
.
append
(
"0"
);
buf
.
append
(
"0"
);
}
buf
.
append
(
Integer
.
toHexString
(
i
));
buf
.
append
(
Integer
.
toHexString
(
i
));
}
}
result
=
buf
.
toString
();
result
=
buf
.
toString
();
...
...
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