Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
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
zengtianlai3
ioc_sixiang_license
Commits
d0a43a61
Commit
d0a43a61
authored
Feb 01, 2023
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
回退一些
parent
8be2a0c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
HmacShaUtils.java
.../src/test/java/iot/sixiang/license/util/HmacShaUtils.java
+59
-0
No files found.
license/src/test/java/iot/sixiang/license/util/HmacShaUtils.java
View file @
d0a43a61
package
iot
.
sixiang
.
license
.
util
;
import
javax.crypto.Mac
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.StandardCharsets
;
/**
* Title: HmacShaUtils
* Description:
*
* @author YFW
* @version V1.0
* @date 2022-03-14
*/
public
class
HmacShaUtils
{
private
static
final
String
HMAC_ALGORITHM
=
"hmacsha1"
;
private
static
final
String
secretKey
=
"90d2fca50ea8ed5472c5776c9fc53699"
;
/**
* 使用HMAC_ALGORITHM加密。
*
* @param content,明文。
* @param secret,密钥。
* @return 密文。
*/
public
static
String
encrypt
(
String
content
,
String
secret
)
{
if
(
PubUtils
.
isNull
(
secret
))
secret
=
secretKey
;
try
{
byte
[]
text
=
content
.
getBytes
(
StandardCharsets
.
UTF_8
);
byte
[]
key
=
secret
.
getBytes
(
StandardCharsets
.
UTF_8
);
SecretKeySpec
secretKey
=
new
SecretKeySpec
(
key
,
HMAC_ALGORITHM
);
Mac
mac
=
Mac
.
getInstance
(
secretKey
.
getAlgorithm
());
mac
.
init
(
secretKey
);
return
byte2hex
(
mac
.
doFinal
(
text
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 二进制转十六进制字符串。
*
* @param b,二进制数组。
* @return 十六进制字符串。
*/
public
static
String
byte2hex
(
byte
[]
b
)
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
n
=
0
;
b
!=
null
&&
n
<
b
.
length
;
n
++)
{
String
stmp
=
Integer
.
toHexString
(
b
[
n
]
&
0XFF
);
if
(
stmp
.
length
()
==
1
)
{
sb
.
append
(
'0'
);
}
sb
.
append
(
stmp
);
}
return
sb
.
toString
().
toUpperCase
();
}
}
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