Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_53854309
数字签名
提交
2dcd005f
数
数字签名
项目概览
qq_53854309
/
数字签名
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
数
数字签名
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2dcd005f
编写于
4月 23, 2023
作者:
H
hml
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
默认的
上级
03b35aa6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
153 addition
and
38 deletion
+153
-38
src/main/java/com/hao/digitalsignature/controller/FileDealController.java
...m/hao/digitalsignature/controller/FileDealController.java
+56
-37
src/main/java/com/hao/digitalsignature/encryption/DownloadMsg.java
...java/com/hao/digitalsignature/encryption/DownloadMsg.java
+51
-0
src/main/resources/application.properties
src/main/resources/application.properties
+1
-1
src/main/resources/static/index.html
src/main/resources/static/index.html
+45
-0
未找到文件。
src/main/java/com/hao/digitalsignature/controller/FileDealController.java
浏览文件 @
2dcd005f
...
@@ -3,6 +3,7 @@ package com.hao.digitalsignature.controller;
...
@@ -3,6 +3,7 @@ package com.hao.digitalsignature.controller;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.hao.digitalsignature.encryption.AES1
;
import
com.hao.digitalsignature.encryption.AES1
;
import
com.hao.digitalsignature.encryption.AESmiyao
;
import
com.hao.digitalsignature.encryption.AESmiyao
;
import
com.hao.digitalsignature.encryption.DownloadMsg
;
import
com.hao.digitalsignature.encryption.RSAEncrypt
;
import
com.hao.digitalsignature.encryption.RSAEncrypt
;
import
com.hao.digitalsignature.entity.Files
;
import
com.hao.digitalsignature.entity.Files
;
import
com.hao.digitalsignature.mapper.FileMapper
;
import
com.hao.digitalsignature.mapper.FileMapper
;
...
@@ -13,13 +14,10 @@ import org.springframework.web.bind.annotation.RequestParam;
...
@@ -13,13 +14,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.ServletContext
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.*
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.SocketException
;
import
java.net.SocketException
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.util.*
;
import
java.util.*
;
...
@@ -70,36 +68,7 @@ public class FileDealController {
...
@@ -70,36 +68,7 @@ public class FileDealController {
// 得到要下载的文件名
// 得到要下载的文件名
fileName
=
fileName
.
substring
(
0
,
fileName
.
length
()-
1
);
fileName
=
fileName
.
substring
(
0
,
fileName
.
length
()-
1
);
try
{
try
{
//获取摘要
QueryWrapper
<
Files
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"picture_realname"
,
fileName
.
split
(
"\\."
)[
0
]);
Files
files
=
fileMapper
.
selectOne
(
wrapper
);
System
.
out
.
println
(
"摘要:"
+
files
.
getDig
().
split
(
";"
)[
2
]);
List
<
String
>
dig
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
files
.
getDig
().
split
(
";"
)));
dig
.
add
(
files
.
getCreatetime
());
String
[]
dig1
=
new
String
[
dig
.
size
()];
dig
.
toArray
(
dig1
);
for
(
int
i
=
0
;
i
<
dig1
.
length
;
i
++)
System
.
out
.
println
(
"正确签名和时间戳"
+
dig1
[
i
]);
//生成AES密钥
String
aesPassword
=
AESmiyao
.
getKey
();
//AES加密
String
encryContent
=
AES1
.
encryptAES
(
files
.
getDig
().
split
(
";"
)[
2
],
aesPassword
);
//对称加密后的签名
dig1
[
2
]=
encryContent
;
for
(
int
i
=
0
;
i
<
dig1
.
length
;
i
++)
System
.
out
.
println
(
"加密摘要的签名和时间戳"
+
dig1
[
i
]);
//发送RSA
System
.
out
.
println
(
Arrays
.
toString
(
dig1
));
String
rsaMsg
=
new
String
();
for
(
int
i
=
0
;
i
<
dig1
.
length
;
i
++){
rsaMsg
+=
dig1
[
i
];
rsaMsg
+=
";"
;
}
byte
[]
rsaEn
=
RSAEncrypt
.
RSAen
(
rsaMsg
.
substring
(
0
,
rsaMsg
.
length
()-
1
));
//RSA解密
String
rsaDe
=
RSAEncrypt
.
RSAde
(
rsaEn
);
...
@@ -123,8 +92,7 @@ public class FileDealController {
...
@@ -123,8 +92,7 @@ public class FileDealController {
}
}
// 处理文件名
// 处理文件名
String
realname
=
fileName
.
substring
(
fileName
.
indexOf
(
"_"
)
+
1
);
String
realname
=
fileName
.
substring
(
fileName
.
indexOf
(
"_"
)
+
1
);
// 设置响应头,控制浏览器下载该文件
// response.setContentType("image/png");
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
realname
,
"UTF-8"
));
+
URLEncoder
.
encode
(
realname
,
"UTF-8"
));
// 读取要下载的文件,保存到文件输入流
// 读取要下载的文件,保存到文件输入流
...
@@ -150,4 +118,55 @@ public class FileDealController {
...
@@ -150,4 +118,55 @@ public class FileDealController {
}
}
}
}
@RequestMapping
(
value
=
"/downloadMsg"
)
public
void
exportKtrAndKjb
(
@RequestBody
String
fileName
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
fileName
=
fileName
.
substring
(
0
,
fileName
.
length
()-
1
);
//获取摘要
try
{
QueryWrapper
<
Files
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"picture_realname"
,
fileName
.
split
(
"\\."
)[
0
]);
Files
files
=
fileMapper
.
selectOne
(
wrapper
);
System
.
out
.
println
(
"文件对象:"
+
files
);
System
.
out
.
println
(
"摘要:"
+
files
.
getDig
().
split
(
";"
)[
2
]);
List
<
String
>
dig
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
files
.
getDig
().
split
(
";"
)));
dig
.
add
(
files
.
getCreatetime
());
String
[]
dig1
=
new
String
[
dig
.
size
()];
dig
.
toArray
(
dig1
);
for
(
int
i
=
0
;
i
<
dig1
.
length
;
i
++)
System
.
out
.
println
(
"正确签名和时间戳"
+
dig1
[
i
]);
//生成AES密钥
String
aesPassword
=
AESmiyao
.
getKey
();
//AES加密
String
encryContent
=
AES1
.
encryptAES
(
files
.
getDig
().
split
(
";"
)[
2
],
aesPassword
);
//对称加密后的签名
dig1
[
2
]=
encryContent
;
for
(
int
i
=
0
;
i
<
dig1
.
length
;
i
++)
System
.
out
.
println
(
"加密摘要的签名和时间戳"
+
dig1
[
i
]);
//发送RSA
System
.
out
.
println
(
Arrays
.
toString
(
dig1
));
String
rsaMsg
=
new
String
();
for
(
int
i
=
0
;
i
<
dig1
.
length
;
i
++){
rsaMsg
+=
dig1
[
i
];
rsaMsg
+=
";"
;
}
System
.
out
.
println
(
rsaMsg
.
length
());
byte
[]
rsaEnf
=
RSAEncrypt
.
RSAen
(
rsaMsg
.
substring
(
0
,
rsaMsg
.
length
()/
2
));
byte
[]
rsaEns
=
RSAEncrypt
.
RSAen
(
rsaMsg
.
substring
(
rsaMsg
.
length
()/
2
));
//RSA解密
String
rsaDef
=
RSAEncrypt
.
RSAde
(
rsaEnf
);
String
rsaDes
=
RSAEncrypt
.
RSAde
(
rsaEns
);
String
recRes
=
rsaDef
+
rsaDes
;
DownloadMsg
.
downloadByStringContent
(
request
,
response
,
fileName
.
split
(
"\\."
)[
0
],
recRes
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"error"
);
}
}
}
}
src/main/java/com/hao/digitalsignature/encryption/DownloadMsg.java
0 → 100644
浏览文件 @
2dcd005f
package
com.hao.digitalsignature.encryption
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
public
class
DownloadMsg
{
public
static
void
downloadByStringContent
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
fileName
,
String
content
)
throws
IOException
{
//设置向浏览器端传送的文件格式
response
.
setContentType
(
"application/octet-stream;charset=utf-8"
);
response
.
setCharacterEncoding
(
"utf-8"
);
if
(
request
.
getHeader
(
"User-Agent"
).
toLowerCase
().
indexOf
(
"firefox"
)
>
0
)
{
// firefox浏览器
fileName
=
new
String
(
fileName
.
getBytes
(
"UTF-8"
),
"ISO8859-1"
);
}
else
if
(
request
.
getHeader
(
"User-Agent"
).
toUpperCase
().
indexOf
(
"MSIE"
)
>
0
)
{
// IE浏览器
fileName
=
URLEncoder
.
encode
(
fileName
,
"UTF-8"
);
}
else
if
(
request
.
getHeader
(
"User-Agent"
).
toUpperCase
().
indexOf
(
"CHROME"
)
>
0
)
{
// 谷歌
fileName
=
new
String
(
fileName
.
getBytes
(
"UTF-8"
),
"ISO8859-1"
);
}
response
.
setHeader
(
"Content-disposition"
,
"attachment; filename="
+
fileName
);
BufferedInputStream
inp
=
null
;
OutputStream
out
=
response
.
getOutputStream
();
try
{
inp
=
new
BufferedInputStream
(
new
ByteArrayInputStream
(
content
.
getBytes
(
"utf-8"
)));
int
len
=
0
;
byte
[]
buf
=
new
byte
[
1024
];
while
((
len
=
inp
.
read
(
buf
))
>
0
)
{
out
.
write
(
buf
,
0
,
len
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
inp
!=
null
)
{
inp
.
close
();
}
if
(
out
!=
null
)
{
out
.
close
();
}
}
}
}
src/main/resources/application.properties
浏览文件 @
2dcd005f
#Ȳ
#Ȳ
spring.devtools.restart.enabled
=
true
spring.devtools.restart.enabled
=
true
spring.devtools.restart.additional-paths
=
src/main/java
spring.devtools.restart.additional-paths
=
src/main/java
server.port
=
808
0
server.port
=
808
1
#ϴļС
#ϴļС
logging.logback.rollingpolicy.max-file-size
=
10MB
logging.logback.rollingpolicy.max-file-size
=
10MB
#swagger
#swagger
...
...
src/main/resources/static/index.html
浏览文件 @
2dcd005f
...
@@ -224,7 +224,52 @@
...
@@ -224,7 +224,52 @@
}
}
});
});
})
})
axios
.
post
(
"
/file/downloadMsg
"
,
f
,).
then
((
res
)
=>
{
console
.
log
(
res
)
// var url = (window.document.location.href+"img/"+res.config.data)
// var a = document.createElement("a");
// a.download = file.picture_name;
// a.href = URL.createObjectURL(blob);
// document.body.appendChild(a)
// a.click();
// URL.revokeObjectURL(a.href) // 释放URL 对象
// document.body.removeChild(a)
// var url = (window.document.location.href+"img/"+res.config.data)
// var that = this
// var fileName = file.picture_name
// this.convertUrlToBase64(url).then(function (base64) {
// var blob = that.convertBase64UrlToBlob(base64); // 转为blob对象
// // 下载
// if (that.myBrowser() == "IE") {
// window.navigator.msSaveBlob(blob, fileName + ".txt");
// } else if (that.myBrowser() == "FF") {
// window.location.href = url;
// } else {
// var a = document.createElement("a");
// a.download = fileName;
// a.href = URL.createObjectURL(blob);
// document.body.appendChild(a)
// a.click();
// URL.revokeObjectURL(a.href) // 释放URL 对象
// document.body.removeChild(a)
// }
// });
this
.
downloadFile
(
res
.
data
,
file
.
picture_name
)
})
},
downloadFile
(
data
,
fileName
){
// data为blob格式
var
blob
=
new
Blob
([
data
]);
var
downloadElement
=
document
.
createElement
(
'
a
'
);
var
href
=
window
.
URL
.
createObjectURL
(
blob
);
downloadElement
.
href
=
href
;
downloadElement
.
download
=
fileName
;
document
.
body
.
appendChild
(
downloadElement
);
downloadElement
.
click
();
document
.
body
.
removeChild
(
downloadElement
);
window
.
URL
.
revokeObjectURL
(
href
);
},
},
// 转换为base64
// 转换为base64
convertUrlToBase64
(
url
)
{
convertUrlToBase64
(
url
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录