Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cash_plugin_toolbox
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikang
cash_plugin_toolbox
Commits
fb584945
Commit
fb584945
authored
Jul 01, 2019
by
Mansoul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getSignKey
parent
c9dfba8c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
0 deletions
+130
-0
src/main/java/com/common/toolbox/app_utils/AuthUtil.java
+27
-0
src/main/java/com/common/toolbox/app_utils/Base64.java
+0
-0
src/main/java/com/common/toolbox/app_utils/ThreeDes.java
+103
-0
No files found.
src/main/java/com/common/toolbox/app_utils/AuthUtil.java
0 → 100644
View file @
fb584945
package
com
.
common
.
toolbox
.
app_utils
;
import
android.text.TextUtils
;
/**
* @author Mansoul
* @create 2019/2/10 20:29
* @des
*/
public
class
AuthUtil
{
/**
* app秘钥解密
*
* @param secretKey display返回的restUrlSignKey字段
* @return
*/
public
static
String
getSignKey
(
String
secretKey
)
{
if
(
TextUtils
.
isEmpty
(
secretKey
))
{
return
""
;
}
byte
[]
decode
=
Base64
.
getDecoder
().
decode
(
secretKey
);
return
new
String
(
ThreeDes
.
decrypt
(
decode
));
}
}
src/main/java/com/common/toolbox/app_utils/Base64.java
0 → 100644
View file @
fb584945
This diff is collapsed.
Click to expand it.
src/main/java/com/common/toolbox/app_utils/ThreeDes.java
0 → 100755
View file @
fb584945
package
com
.
common
.
toolbox
.
app_utils
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
public
class
ThreeDes
{
/**
* @param args在java中调用sun公司提供的3DES加密解密算法时,需要使
* 用到$JAVA_HOME/jre/lib/目录下如下的4个jar包:
* jce.jar
* security/US_export_policy.jar
* security/local_policy.jar
* ext/sunjce_provider.jar
*/
private
static
final
String
ALGORITHM
=
"DESede"
;
//定义加密算法,可用 DES,DESede,Blowfish
private
static
final
String
DEFAULT_KEY
=
"starwin123456"
;
//keyByte为加密密钥,长度为24字节
//src为被加密的数据缓冲区(源)
public
static
byte
[]
encrypt
(
byte
[]
keyByte
,
byte
[]
src
)
{
try
{
//生成密钥
SecretKey
deskey
=
new
SecretKeySpec
(
keyByte
,
ALGORITHM
);
//加密
Cipher
c1
=
Cipher
.
getInstance
(
ALGORITHM
);
c1
.
init
(
Cipher
.
ENCRYPT_MODE
,
deskey
);
return
c1
.
doFinal
(
src
);
//在单一方面的加密或解密
}
catch
(
NoSuchAlgorithmException
e1
)
{
e1
.
printStackTrace
();
}
catch
(
javax
.
crypto
.
NoSuchPaddingException
e2
)
{
e2
.
printStackTrace
();
}
catch
(
Exception
e3
)
{
e3
.
printStackTrace
();
}
return
null
;
}
//keyByte为加密密钥,长度为24字节
//src为加密后的缓冲区
public
static
byte
[]
decrypt
(
byte
[]
keyByte
,
byte
[]
src
)
{
try
{
//生成密钥
SecretKey
destKey
=
new
SecretKeySpec
(
keyByte
,
ALGORITHM
);
//解密
Cipher
c1
=
Cipher
.
getInstance
(
ALGORITHM
);
c1
.
init
(
Cipher
.
DECRYPT_MODE
,
destKey
);
return
c1
.
doFinal
(
src
);
}
catch
(
NoSuchAlgorithmException
e1
)
{
e1
.
printStackTrace
();
}
catch
(
javax
.
crypto
.
NoSuchPaddingException
e2
)
{
e2
.
printStackTrace
();
}
catch
(
Exception
e3
)
{
e3
.
printStackTrace
();
}
return
null
;
}
public
static
byte
[]
decrypt
(
byte
[]
src
)
{
return
decrypt
(
hex
(
DEFAULT_KEY
),
src
);
}
private
static
String
md5Hex
(
String
string
)
{
if
(
string
==
null
||
string
.
length
()
==
0
)
{
return
""
;
}
MessageDigest
md5
=
null
;
try
{
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
bytes
=
md5
.
digest
(
string
.
getBytes
());
StringBuilder
result
=
new
StringBuilder
();
for
(
byte
b
:
bytes
)
{
String
temp
=
Integer
.
toHexString
(
b
&
0xff
);
if
(
temp
.
length
()
==
1
)
{
temp
=
"0"
+
temp
;
}
result
.
append
(
temp
);
}
return
result
.
toString
();
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
private
static
byte
[]
hex
(
String
secretKey
)
{
String
f
=
md5Hex
(
secretKey
);
byte
[]
bytes
=
f
.
getBytes
();
byte
[]
enk
=
new
byte
[
24
];
for
(
int
i
=
0
;
i
<
24
;
i
++)
{
enk
[
i
]
=
bytes
[
i
];
}
return
enk
;
}
}
\ 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