Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
lic
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
inroi
lic
Commits
fbb2eec0
提交
fbb2eec0
authored
9月 27, 2022
作者:
inroi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
微调
上级
1294d557
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
64 行增加
和
9 行删除
+64
-9
LicVerificationController.java
...java/com/system/controller/LicVerificationController.java
+1
-1
ILicVerificationService.java
...main/java/com/system/serivce/ILicVerificationService.java
+1
-2
LicVerificationServiceImpl.java
...a/com/system/serivce/impl/LicVerificationServiceImpl.java
+22
-3
RsaUtil.java
lic-system/src/main/java/com/system/utils/RsaUtil.java
+40
-3
没有找到文件。
lic-system/src/main/java/com/system/controller/LicVerificationController.java
浏览文件 @
fbb2eec0
...
...
@@ -43,7 +43,7 @@ public class LicVerificationController {
@ApiOperation
(
"Lic在线验证"
)
@PostMapping
(
"/lic/online/verification"
)
public
RestResponse
licOnlineVerification
(
@RequestBody
LicOnlineVerificationInVo
inVo
)
{
public
String
licOnlineVerification
(
@RequestBody
LicOnlineVerificationInVo
inVo
)
{
return
licVerificationService
.
licOnlineVerification
(
inVo
);
}
...
...
lic-system/src/main/java/com/system/serivce/ILicVerificationService.java
浏览文件 @
fbb2eec0
package
com
.
system
.
serivce
;
import
com.system.transfer.response.RestResponse
;
import
com.system.transfer.verification.*
;
/**
...
...
@@ -37,7 +36,7 @@ public interface ILicVerificationService {
* @param inVo 条件
* @return 结果
*/
RestResponse
licOnlineVerification
(
LicOnlineVerificationInVo
inVo
);
String
licOnlineVerification
(
LicOnlineVerificationInVo
inVo
);
}
lic-system/src/main/java/com/system/serivce/impl/LicVerificationServiceImpl.java
浏览文件 @
fbb2eec0
...
...
@@ -60,13 +60,17 @@ public class LicVerificationServiceImpl implements ILicVerificationService {
}
@Override
public
RestResponse
licOnlineVerification
(
LicOnlineVerificationInVo
inVo
)
{
public
String
licOnlineVerification
(
LicOnlineVerificationInVo
inVo
)
{
String
result
;
try
{
result
=
RsaUtil
.
decryptByPrivateKeyToLong
(
inVo
.
getData
(),
rsaKeyConstant
.
getPrivateKey
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
RestResponse
.
fail
(
"Lic文件信息解密失败"
);
try
{
return
RsaUtil
.
encryptByPrivateKeyToLong
(
JSON
.
toJSONString
(
RestResponse
.
fail
(
"Lic文件信息解密失败"
)),
rsaKeyConstant
.
getPrivateKey
());
}
catch
(
Exception
ex
)
{
return
""
;
}
}
LicOnlineVerificationLogCreateInVo
request
=
new
LicOnlineVerificationLogCreateInVo
();
...
...
@@ -93,8 +97,23 @@ public class LicVerificationServiceImpl implements ILicVerificationService {
request
.
setResponse
(
JsonUtil
.
toString
(
response
));
}
try
{
response
.
setData
(
RsaUtil
.
sign
(
rsaKeyConstant
.
getPrivateKey
(),
JsonUtil
.
toString
(
response
)));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
try
{
return
RsaUtil
.
encryptByPrivateKeyToLong
(
JSON
.
toJSONString
(
RestResponse
.
fail
(
"Lic文件信息签名失败"
)),
rsaKeyConstant
.
getPrivateKey
());
}
catch
(
Exception
ex
)
{
return
""
;
}
}
licVerificationMapper
.
licOnlineVerificationLogCreate
(
request
);
return
response
;
try
{
return
RsaUtil
.
encryptByPrivateKeyToLong
(
JSON
.
toJSONString
(
response
),
rsaKeyConstant
.
getPrivateKey
());
}
catch
(
Exception
ex
)
{
return
""
;
}
}
private
RestResponse
purchaseToResult
(
Map
<
String
,
Object
>
map
)
{
...
...
lic-system/src/main/java/com/system/utils/RsaUtil.java
浏览文件 @
fbb2eec0
...
...
@@ -3,9 +3,7 @@ package com.system.utils;
import
javax.crypto.Cipher
;
import
java.io.ByteArrayOutputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.security.KeyFactory
;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
import
java.security.*
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
import
java.util.Base64
;
...
...
@@ -23,6 +21,11 @@ public class RsaUtil {
public
static
final
String
KEY_ALGORITHM
=
"RSA"
;
/**
* 签名算法
*/
public
static
final
String
SIGNATURE_ALGORITHM
=
"SHA256withRSA"
;
/**
* RSA最大加密明文大小
*/
private
static
final
int
MAX_ENCRYPT_BLOCK
=
117
;
...
...
@@ -191,5 +194,39 @@ public class RsaUtil {
return
new
String
(
outputStream
.
toByteArray
());
}
/**
* 私钥签名
*/
public
static
String
sign
(
String
privateKey
,
String
plainText
)
throws
Exception
{
//64位解码加密后的字符串
byte
[]
byteKey
=
Base64
.
getDecoder
().
decode
(
privateKey
);
PKCS8EncodedKeySpec
pkcs8EncodedKeySpec
=
new
PKCS8EncodedKeySpec
(
byteKey
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
KEY_ALGORITHM
);
//签名
PrivateKey
key
=
keyFactory
.
generatePrivate
(
pkcs8EncodedKeySpec
);
Signature
signature
=
Signature
.
getInstance
(
SIGNATURE_ALGORITHM
);
signature
.
initSign
(
key
);
signature
.
update
(
plainText
.
getBytes
());
return
Base64
.
getEncoder
().
encodeToString
(
signature
.
sign
());
}
/**
* 公钥验签
*/
public
static
boolean
verifySign
(
String
publicKey
,
String
plainText
,
String
signStr
)
throws
Exception
{
//64位解码加密后的字符串
byte
[]
byteKey
=
Base64
.
getDecoder
().
decode
(
publicKey
);
X509EncodedKeySpec
x509EncodedKeySpec
=
new
X509EncodedKeySpec
(
byteKey
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
KEY_ALGORITHM
);
//验签
PublicKey
key
=
keyFactory
.
generatePublic
(
x509EncodedKeySpec
);
Signature
verifySign
=
Signature
.
getInstance
(
SIGNATURE_ALGORITHM
);
verifySign
.
initVerify
(
key
);
verifySign
.
update
(
plainText
.
getBytes
());
return
verifySign
.
verify
(
Base64
.
getDecoder
().
decode
(
signStr
));
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论