Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
estateplat-encrypt
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
狄熙卜
estateplat-encrypt
Commits
3978e74d
提交
3978e74d
authored
4月 08, 2024
作者:
狄熙卜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改解密报错输出
上级
27fea82b
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
21 行删除
+40
-21
GmSm4Util.java
...ain/java/cn/gtmap/bdcdj/core/encrypt/utils/GmSm4Util.java
+40
-21
没有找到文件。
src/main/java/cn/gtmap/bdcdj/core/encrypt/utils/GmSm4Util.java
浏览文件 @
3978e74d
...
...
@@ -155,7 +155,7 @@ public class GmSm4Util {
}
}
public
static
String
decryptWithUserSalt
(
String
hexKey
,
String
cipherText
,
String
salt
,
String
encoding
)
throws
Exception
{
public
static
String
decryptWithUserSalt
(
String
hexKey
,
String
cipherText
,
String
salt
,
String
encoding
)
{
if
(
hexKey
.
length
()
==
16
)
{
hexKey
=
toHexString
(
hexKey
);
}
...
...
@@ -163,64 +163,83 @@ public class GmSm4Util {
byte
[]
keyData
=
ByteUtils
.
fromHexString
(
hexKey
);
byte
[]
cipherData
;
byte
[]
srcData
;
String
result
=
""
;
if
(
StringUtils
.
startsWithIgnoreCase
(
cipherText
,
salt
))
{
if
(
StringUtils
.
endsWith
(
cipherText
,
"等"
))
{
String
realCipherText
=
StringUtils
.
removeEnd
(
StringUtils
.
removeStartIgnoreCase
(
cipherText
,
salt
),
"等"
);
srcData
=
ByteUtils
.
fromHexString
(
realCipherText
);
try
{
srcData
=
decrypt_Ecb_Padding
(
keyData
,
srcData
);
return
new
String
(
srcData
,
encoding
)
+
"等"
;
result
=
new
String
(
srcData
,
encoding
)
+
"等"
;
}
catch
(
Exception
e
){
LOGGER
.
error
(
"解密失败,对应的密文内容为 "
+
cipherText
);
}
return
result
;
}
else
{
cipherData
=
ByteUtils
.
fromHexString
(
StringUtils
.
removeStartIgnoreCase
(
cipherText
,
salt
));
try
{
srcData
=
decrypt_Ecb_Padding
(
keyData
,
cipherData
);
return
new
String
(
srcData
,
encoding
);
result
=
new
String
(
srcData
,
encoding
);
}
catch
(
Exception
e
){
LOGGER
.
error
(
"解密失败,对应的密文内容为 "
+
cipherText
);
}
return
result
;
}
}
else
{
cipherData
=
ByteUtils
.
fromHexString
(
cipherText
);
try
{
srcData
=
decrypt_Ecb_Padding
(
keyData
,
cipherData
);
return
new
String
(
srcData
,
encoding
);
result
=
new
String
(
srcData
,
encoding
);
}
catch
(
Exception
e
){
LOGGER
.
error
(
"解密失败,对应的密文内容为 "
+
cipherText
);
}
return
result
;
}
}
public
static
String
decryptEcb
(
String
cipherText
)
throws
Exception
{
public
static
String
decryptEcb
(
String
cipherText
){
byte
[]
keyData
=
ByteUtils
.
fromHexString
(
"645B0A010D939BD614A620BCAF645470"
);
byte
[]
cipherData
;
byte
[]
srcData
;
String
result
=
""
;
if
(
StringUtils
.
startsWithIgnoreCase
(
cipherText
,
SaltsEnum
.
GM_SM4_SALTS
.
getSalt
()))
{
if
(
StringUtils
.
endsWith
(
cipherText
,
"等"
))
{
String
realCipherText
=
StringUtils
.
removeEnd
(
StringUtils
.
removeStartIgnoreCase
(
cipherText
,
SaltsEnum
.
GM_SM4_SALTS
.
getSalt
()),
"等"
);
srcData
=
ByteUtils
.
fromHexString
(
realCipherText
);
try
{
srcData
=
decrypt_Ecb_Padding
(
keyData
,
srcData
);
return
new
String
(
srcData
,
"UTF-8"
)
+
"等"
;
result
=
new
String
(
srcData
,
"UTF-8"
)
+
"等"
;
}
catch
(
Exception
e
){
LOGGER
.
error
(
"解密失败,对应的密文内容为 "
+
cipherText
);
}
return
result
;
}
else
{
cipherData
=
ByteUtils
.
fromHexString
(
StringUtils
.
removeStartIgnoreCase
(
cipherText
,
SaltsEnum
.
GM_SM4_SALTS
.
getSalt
()));
try
{
srcData
=
decrypt_Ecb_Padding
(
keyData
,
cipherData
);
return
new
String
(
srcData
,
"UTF-8"
);
result
=
new
String
(
srcData
,
"UTF-8"
);
}
catch
(
Exception
e
){
LOGGER
.
error
(
"解密失败,对应的密文内容为 "
+
cipherText
);
}
return
result
;
}
}
else
{
cipherData
=
ByteUtils
.
fromHexString
(
cipherText
);
try
{
srcData
=
decrypt_Ecb_Padding
(
keyData
,
cipherData
);
return
new
String
(
srcData
,
"UTF-8"
);
result
=
new
String
(
srcData
,
"UTF-8"
);
}
catch
(
Exception
e
){
LOGGER
.
error
(
"解密失败,对应的密文内容为 "
+
cipherText
);
}
return
result
;
}
}
public
static
byte
[]
decrypt_Ecb_Padding
(
byte
[]
key
,
byte
[]
cipherText
)
throws
Exception
{
Cipher
cipher
=
null
;
try
{
cipher
=
generateEcbCipher
(
"SM4/ECB/PKCS5Padding"
,
2
,
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
"加密字段错误,请联系管理员检查,error:0"
.
getBytes
(
"UTF-8"
);
}
if
(
cipher
!=
null
)
{
try
{
return
cipher
.
doFinal
(
cipherText
);
}
catch
(
IllegalBlockSizeException
e
)
{
LOGGER
.
error
(
"解密失败,IllegalBlockSizeException"
);
throw
e
;
}
catch
(
BadPaddingException
e
)
{
LOGGER
.
error
(
"解密失败,BadPaddingException"
);
throw
e
;
}
}
else
{
LOGGER
.
info
(
"解密失败"
);
return
"加密字段错误,请联系管理员检查,error:3"
.
getBytes
(
"UTF-8"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论