Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_53854309
数字签名
提交
ca9d0719
数
数字签名
项目概览
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,发现更多精彩内容 >>
提交
ca9d0719
编写于
5月 03, 2023
作者:
qq_53854309
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
图片功能基本实现
上级
7fee76cd
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
268 addition
and
59 deletion
+268
-59
src/main/java/com/hao/digitalsignature/controller/FileDealController.java
...m/hao/digitalsignature/controller/FileDealController.java
+14
-1
src/main/java/com/hao/digitalsignature/controller/FilesController.java
.../com/hao/digitalsignature/controller/FilesController.java
+42
-26
src/main/java/com/hao/digitalsignature/encryption/RSAEncrypt.java
.../java/com/hao/digitalsignature/encryption/RSAEncrypt.java
+6
-4
src/main/java/com/hao/digitalsignature/entity/Download.java
src/main/java/com/hao/digitalsignature/entity/Download.java
+49
-0
src/main/java/com/hao/digitalsignature/mapper/DownloadMapper.java
.../java/com/hao/digitalsignature/mapper/DownloadMapper.java
+14
-0
src/main/resources/application.properties
src/main/resources/application.properties
+2
-0
src/main/resources/static/index.html
src/main/resources/static/index.html
+141
-28
未找到文件。
src/main/java/com/hao/digitalsignature/controller/FileDealController.java
浏览文件 @
ca9d0719
...
...
@@ -5,7 +5,9 @@ import com.hao.digitalsignature.encryption.AES1;
import
com.hao.digitalsignature.encryption.AESmiyao
;
import
com.hao.digitalsignature.encryption.DownloadMsg
;
import
com.hao.digitalsignature.encryption.RSAEncrypt
;
import
com.hao.digitalsignature.entity.Download
;
import
com.hao.digitalsignature.entity.Files
;
import
com.hao.digitalsignature.mapper.DownloadMapper
;
import
com.hao.digitalsignature.mapper.FileMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -30,6 +32,9 @@ public class FileDealController {
@Autowired
private
FileMapper
fileMapper
;
@Autowired
private
DownloadMapper
downloadMapper
;
@RequestMapping
(
value
=
"upload"
)
public
String
upload
(
@RequestParam
(
"file"
)
MultipartFile
pic
)
throws
SocketException
,
IOException
{
String
newName
=
""
;
...
...
@@ -135,6 +140,14 @@ public class FileDealController {
System
.
out
.
println
(
"正确签名和时间戳"
+
dig1
[
i
]);
//生成AES密钥
String
aesPassword
=
AESmiyao
.
getKey
();
if
(
files
.
getPicture_realname
()!=
null
){
Download
download
=
new
Download
(
0
,
files
.
getPicture_realname
(),
aesPassword
);
System
.
out
.
println
(
download
);
downloadMapper
.
insert
(
download
);
System
.
out
.
println
(
"成功"
);
}
else
{
System
.
out
.
println
(
"有了"
);
}
//AES加密
String
encryContent
=
AES1
.
encryptAES
(
files
.
getDig
().
split
(
";"
)[
2
],
aesPassword
);
//对称加密后的签名
...
...
@@ -156,7 +169,7 @@ public class FileDealController {
String
rsaDef
=
RSAEncrypt
.
RSAde
(
rsaEnf
);
String
rsaDes
=
RSAEncrypt
.
RSAde
(
rsaEns
);
String
recRes
=
rsaDef
+
rsaDes
;
System
.
out
.
println
(
'6'
);
DownloadMsg
.
downloadByStringContent
(
request
,
response
,
fileName
.
split
(
"\\."
)[
0
],
recRes
);
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/hao/digitalsignature/controller/FilesController.java
浏览文件 @
ca9d0719
package
com.hao.digitalsignature.controller
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.hao.digitalsignature.encryption.AES1
;
import
com.hao.digitalsignature.encryption.DSASign
;
import
com.hao.digitalsignature.entity.Download
;
import
com.hao.digitalsignature.entity.User
;
import
com.hao.digitalsignature.mapper.DownloadMapper
;
import
com.hao.digitalsignature.mapper.UserMapper
;
import
com.sun.org.apache.xerces.internal.impl.dv.util.Base64
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -24,29 +28,10 @@ public class FilesController {
@Autowired
private
FileMapper
fileMapper
;
// @PostMapping("/upload")
// public String up(String name, MultipartFile photo, HttpServletRequest request) throws IOException{
// //自定文件名
// System.out.println(name);
// //文件原名
// System.out.println(photo.getOriginalFilename());
// //文件类型
// System.out.println(photo.getContentType());
//
// String path=request.getServletContext().getRealPath("/upload/");
// System.out.println(path);
// saveFile(photo,path);
// return "上传成功";
// }
//
// public void saveFile(MultipartFile photo,String path) throws IOException{
// File dir = new File(path);
// if (!dir.exists()){
// dir.mkdir();
// }
// File file = new File(path+photo.getOriginalFilename());
// photo.transferTo(file);
// }
@Autowired
private
DownloadMapper
downloadMapper
;
@PutMapping
(
"/file/update"
)
public
String
update
(
int
id
,
String
name
){
Files
file
=
fileMapper
.
selectById
(
id
);
...
...
@@ -89,14 +74,45 @@ public class FilesController {
System
.
out
.
println
(
file
);
if
(
file
.
getCreatetime
().
equals
(
str
[
4
])){
System
.
out
.
println
(
"success"
);
QueryWrapper
<
Download
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"picture_realname"
,
file
.
getPicture_realname
());
Download
download
=
downloadMapper
.
selectOne
(
queryWrapper
);
String
aes
=
download
.
getaes
();
return
aes
;
}
else
{
System
.
out
.
println
(
"failed"
);
}
// str[3];
return
"0"
;
}
@PostMapping
(
value
=
"/file/encrypt"
)
public
String
encrypt
(
@RequestBody
String
str
){
String
[]
strs
=
str
.
substring
(
1
,
str
.
length
()-
1
).
split
(
";"
);
for
(
int
i
=
0
;
i
<
strs
.
length
;
i
++)
System
.
out
.
println
(
strs
[
i
]);
try
{
String
encryContent
=
AES1
.
decryptAES
(
strs
[
2
],
strs
[
4
]);
strs
[
2
]=
encryContent
;
String
newStr
=
new
String
();
for
(
int
i
=
0
;
i
<
strs
.
length
-
3
;
i
++)
{
newStr
+=
strs
[
i
];
newStr
+=
";"
;
}
newStr
=
newStr
.
substring
(
0
,
newStr
.
length
()-
1
);
QueryWrapper
<
Files
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"picture_realname"
,
strs
[
5
]);
Files
files
=
fileMapper
.
selectOne
(
wrapper
);
System
.
out
.
println
(
files
.
getDig
());
System
.
out
.
println
(
newStr
);
if
(
files
.
getDig
().
equals
(
newStr
)){
return
"success"
;
}
else
{
return
"failed"
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
"error"
;
}
@GetMapping
(
"/file/findAll"
)
public
List
<
Files
>
find
(){
...
...
src/main/java/com/hao/digitalsignature/encryption/RSAEncrypt.java
浏览文件 @
ca9d0719
...
...
@@ -331,9 +331,10 @@ public class RSAEncrypt {
}
return
stringBuilder
.
toString
();
}
//解密
public
static
String
RSAde
(
byte
[]
cipherData
)
throws
Exception
{
String
publicPath
=
"C:\\Users\\
w10
"
;
//公匙存放位置
String
privatePath
=
"C:\\Users\\
w10
"
;
//私匙存放位置
String
publicPath
=
"C:\\Users\\
10908
"
;
//公匙存放位置
String
privatePath
=
"C:\\Users\\
10908
"
;
//私匙存放位置
Base64
base64
=
new
Base64
();
String
cipher
=
new
String
(
base64
.
encode
(
cipherData
));
// 私钥解密过程
...
...
@@ -343,9 +344,10 @@ public class RSAEncrypt {
return
restr
;
}
//加密
public
static
byte
[]
RSAen
(
String
key
)
throws
Exception
{
String
publicPath
=
"C:\\Users\\
w10
"
;
//公匙存放位置
String
privatePath
=
"C:\\Users\\
w10
"
;
//私匙存放位置
String
publicPath
=
"C:\\Users\\
10908
"
;
//公匙存放位置
String
privatePath
=
"C:\\Users\\
10908
"
;
//私匙存放位置
Base64
base64
=
new
Base64
();
String
signKey
=
key
;
// 公钥加密过程
...
...
src/main/java/com/hao/digitalsignature/entity/Download.java
0 → 100644
浏览文件 @
ca9d0719
package
com.hao.digitalsignature.entity
;
import
com.baomidou.mybatisplus.annotation.*
;
@TableName
(
value
=
"downpicture"
)
public
class
Download
{
private
Integer
user_id
;
private
String
picture_realname
;
private
String
aes
;
public
Download
(
Integer
user_id
,
String
picture_realname
,
String
aes
)
{
this
.
user_id
=
user_id
;
this
.
picture_realname
=
picture_realname
;
this
.
aes
=
aes
;
}
public
Integer
getUser_id
()
{
return
user_id
;
}
public
void
setUser_id
(
Integer
user_id
)
{
this
.
user_id
=
user_id
;
}
public
String
getPicture_realname
()
{
return
picture_realname
;
}
public
void
setPicture_realname
(
String
picture_realname
)
{
this
.
picture_realname
=
picture_realname
;
}
public
String
getaes
()
{
return
aes
;
}
public
void
setaes
(
String
aes
)
{
this
.
aes
=
aes
;
}
@Override
public
String
toString
()
{
return
"Download{"
+
"user_id="
+
user_id
+
", picture_realname='"
+
picture_realname
+
'\''
+
", aes='"
+
aes
+
'\''
+
'}'
;
}
}
src/main/java/com/hao/digitalsignature/mapper/DownloadMapper.java
0 → 100644
浏览文件 @
ca9d0719
package
com.hao.digitalsignature.mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.hao.digitalsignature.entity.Download
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Select
;
import
org.springframework.stereotype.Repository
;
@Mapper
@Repository
public
interface
DownloadMapper
extends
BaseMapper
<
Download
>
{
@Select
(
"select * from downpicture where BINARY picture_realname=#{picture_realname}"
)
Download
find
(
String
id
);
}
src/main/resources/application.properties
浏览文件 @
ca9d0719
...
...
@@ -4,6 +4,8 @@ spring.devtools.restart.additional-paths=src/main/java
server.port
=
8081
#ϴļС
logging.logback.rollingpolicy.max-file-size
=
10MB
spring.servlet.multipart.max-file-size
=
10MB
spring.servlet.multipart.max-request-size
=
100MB
#swagger
spring.mvc.pathmatch.matching-strategy
=
ant_path_matcher
...
...
src/main/resources/static/index.html
浏览文件 @
ca9d0719
...
...
@@ -89,6 +89,7 @@
:on-remove=
"handleRemove"
:on-success=
"handlePicturePreview"
:http-request=
"uploadFile"
:before-upload=
"beforeAvatarUpload"
>
<i
slot=
"default"
class=
"el-icon-plus"
></i>
<div
slot=
"file"
slot-scope=
"{file}"
>
...
...
@@ -114,13 +115,39 @@
</span>
</div>
</el-upload>
</el-form-item>
<el-form-item>
<el-button
type=
"primary"
@
click=
"handleEdit()"
>
立即创建
</el-button>
<el-button
@
click=
"dialogFormVisible = false,resetForm()"
>
取消
</el-button>
</el-form-item>
</el-form>
.
</el-dialog>
<el-dialog
:visible.sync=
"dialogVisible"
>
<img
width=
"100%"
:src=
"dialogImageUrl"
alt=
""
>
</el-dialog>
<el-dialog
title=
"解密签名"
:visible.sync=
"dialogFormVisible2"
>
<el-form
:model=
"formData"
label-width=
"80px"
:rules=
"rules"
ref=
"dforms"
>
<el-form-item
label=
"AES密钥"
:rules=
"rules.AES"
prop=
"AES"
>
<el-input
v-model=
"formData.AES"
></el-input>
</el-form-item>
<el-form-item
label=
"签名文件"
:rules=
"rules.dig"
prop=
"dig"
>
<el-upload
class=
"digFile"
action=
"#"
:auto-upload=
"false"
accept=
"text/plain"
:limit=
"1"
:file-list=
"digList"
:on-change=
"uploadDig"
ref=
"myDig"
>
<el-button
size=
"small"
type=
"primary"
>
上传签名文件
</el-button>
</el-upload>
</el-form-item>
<el-form-item>
<el-button
type=
"primary"
@
click=
"handleE
dit()"
>
立即创建
</el-button>
<el-button
@
click=
"dialogFormVisible
= false,resetForm
()"
>
取消
</el-button>
<el-button
type=
"primary"
@
click=
"handleE
ncryptionDig()"
>
立即解密
</el-button>
<el-button
@
click=
"dialogFormVisible
2 = false,resetDig
()"
>
取消
</el-button>
</el-form-item>
</el-form>
.
</el-dialog>
...
...
@@ -137,14 +164,15 @@
</el-table-column>
<el-table-column
label=
"图片"
align=
"center"
>
<div
slot-scope=
"scope"
>
<img
:src=
"'./img/'+scope.row.picture_realname+'.'+scope.row.picture_type"
width=
"100px"
onerror=
"this.src='./img/丢失.jpg;this.οnerrοr=null'"
/>
<img
:src=
"'./img/'+scope.row.picture_realname+'.'+scope.row.picture_type"
@
click=
"handlePictureCardPreviewTable(scope.row)"
width=
"100px"
onerror=
"this.src='./img/丢失.jpg;this.οnerrοr=null'"
/>
</div>
</el-table-column>
<el-table-column
prop=
"createtime"
label=
"创建时间"
>
</el-table-column>
<el-table-column
label=
"功能"
width=
"
18
0"
>
<el-table-column
label=
"功能"
width=
"
30
0"
>
<div
slot-scope=
"scope"
style=
"display: flex;justify-content: space-around"
>
<el-button
type=
"primary"
size=
"mini"
@
click=
"handleDownload(scope.row)"
>
下载
</el-button>
<el-upload
class=
"upload-demo"
action=
"#"
...
...
@@ -153,10 +181,12 @@
:show-file-list=
"false"
accept=
"text/plain"
:limit=
"1"
:file-list=
"verifyList"
>
<el-button
size=
"small"
type=
"primary"
>
验证
</el-button>
:file-list=
"verifyList"
ref=
"myVerify"
>
<el-button
size=
"small"
type=
"primary"
>
验证时间戳
</el-button>
</el-upload>
<el-button
type=
"primary"
size=
"mini"
@
click=
"handleDig(scope.row)"
>
解密签名
</el-button>
</div>
</el-table-column>
<el-empty
description=
"暂无信息"
></el-empty>
...
...
@@ -185,12 +215,17 @@
el
:
'
#app
'
,
data
()
{
return
{
rname
:
''
,
par
:
''
,
AES
:
''
,
dig
:
''
,
filelist
:
[],
digList
:[],
verify
:{},
verifyList
:[],
formData
:
{},
dialogFormVisible
:
false
,
dialogFormVisible2
:
false
,
dialogFormVisible4Edit
:
false
,
dialogImageUrl
:
''
,
dialogVisible
:
false
,
...
...
@@ -205,6 +240,8 @@
PageSize
:
3
,
rules
:
{
picture_name
:
[{
required
:
true
,
message
:
'
请输入图片名称
'
,
trigger
:
'
blur
'
}],
AES
:
[{
required
:
true
,
message
:
'
请输入AES密钥
'
,
trigger
:
'
blur
'
}],
dig
:
[{
required
:
true
,
message
:
'
请上传签名文件
'
,
trigger
:
'
blur
'
}],
picture
:[{
required
:
true
,
message
:
'
请上传图片
'
,
trigger
:
'
blur
'
}]
},
}
...
...
@@ -222,6 +259,7 @@
// 改变默认的页数
this
.
currentPage
=
val
},
handleOpen
(
key
,
keyPath
)
{
console
.
log
(
key
,
keyPath
);
...
...
@@ -231,22 +269,38 @@
},
handlePicturePreview
(
file
)
{
console
.
log
(
file
)
console
.
log
(
6
)
this
.
par
=
file
.
raw
;
const
isLt2M
=
file
.
size
/
1024
/
1024
<
10
;
if
(
!
isLt2M
)
{
this
.
$message
.
error
(
'
上传头像图片大小不能超过 10MB!
'
);
this
.
clearFiles
();
return
isLt2M
;
}
},
handlePreview
(
file
)
{
console
.
log
(
file
);
},
handleRemove
(
file
)
{
console
.
log
(
file
)
},
clearFiles
()
{
this
.
$refs
[
'
mYupload
'
].
clearFiles
();
},
clearDig
()
{
this
.
$refs
[
'
myDig
'
].
clearFiles
();
},
handlePictureCardPreview
(
file
)
{
this
.
dialogImageUrl
=
file
.
url
;
this
.
dialogVisible
=
true
;
},
handlePictureCardPreviewTable
(
file
)
{
this
.
dialogImageUrl
=
window
.
document
.
location
.
href
+
'
./img/
'
+
file
.
picture_realname
+
'
.
'
+
file
.
picture_type
;
this
.
dialogVisible
=
true
;
},
handleDownload
(
file
)
{
let
f
=
file
.
picture_realname
+
"
.
"
+
file
.
picture_type
axios
.
post
(
"
/file/download
"
,
f
,).
then
((
result
)
=>
{
...
...
@@ -386,9 +440,18 @@
//重置表单
resetForm
()
{
this
.
formData
=
{};
//this.$refs['form'].clearValidate();
//this.$refs['myDig'].clearValidate();
this
.
$nextTick
(()
=>
{
this
.
$refs
.
mYupload
.
clearFiles
()
})
},
//重置解密
resetDig
()
{
this
.
formData
=
{};
this
.
$nextTick
(()
=>
{
this
.
$refs
.
forms
.
clearValidate
()
this
.
$refs
.
myDig
.
clearFiles
()
})
},
//弹出添加窗口
...
...
@@ -396,11 +459,20 @@
this
.
resetForm
();
this
.
dialogFormVisible
=
true
;
},
uploadDig
(
file
){
this
.
dig
=
file
.
raw
;
},
handleDig
(
file
)
{
this
.
rname
=
file
.
picture_realname
;
this
.
resetDig
();
this
.
dialogFormVisible2
=
true
;
},
handleVerify
()
{
this
.
resetForm
();
this
.
dialogFormVisible4Edit
=
true
;
},
openFile
(
file
,
name
)
{
let
this_vue
=
this
//验证的文件
console
.
log
(
name
.
picture_name
)
var
reader
=
new
FileReader
();
...
...
@@ -411,11 +483,52 @@
var
p
=
name
.
picture_id
+
'
;
'
+
reader
.
result
axios
.
post
(
"
/file/verify
"
,
p
,{
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
data
'
:
'
JSON.stringify(Data)
'
}}).
then
((
res
)
=>
{
console
.
log
(
res
)
if
(
res
.
data
!=
0
){
this_vue
.
$alert
(
'
AES密钥(请复制):
'
+
res
.
data
,
'
验证成功
'
,
{
confirmButtonText
:
'
确定
'
,
});
}
else
{
this_vue
.
$alert
(
"
请重新确认
"
,
'
验证错误
'
,
{
confirmButtonText
:
'
确定
'
,
});
}
})
}
};
reader
.
readAsText
(
file
.
raw
);
this
.
$refs
[
'
myVerify
'
].
clearFiles
();
},
handleEncryptionDig
(){
let
file
=
this
.
dig
let
this_vue
=
this
let
aes
=
this
.
formData
.
AES
+
"
;
"
+
this
.
rname
;
let
reader
=
new
FileReader
();
reader
.
onload
=
function
()
{
if
(
reader
.
result
)
{
//打印文件内容
let
str
=
reader
.
result
+
aes
;
axios
.
post
(
"
/file/encrypt
"
,
str
,{
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
data
'
:
'
JSON.stringify(Data)
'
}}).
then
((
res
)
=>
{
if
(
res
.
data
==
"
success
"
){
this_vue
.
$alert
(
'
文件签名正确!
'
,
'
验证成功
'
,
{
confirmButtonText
:
'
确定
'
,
});
}
else
if
(
res
.
data
==
"
failed
"
){
this_vue
.
$alert
(
'
文件与签名不符,请重新检查!
'
,
'
验证出错
'
,
{
confirmButtonText
:
'
确定
'
,
});
}
else
{
this_vue
.
$alert
(
'
服务器可能出错,或密钥格式错误,请稍后重试!
'
,
'
验证出错
'
,
{
confirmButtonText
:
'
确定
'
,
});
}
});
}
};
reader
.
readAsText
(
file
);
this
.
dialogFormVisible2
=
false
;
this
.
rname
=
null
;
this
.
resetDig
();
},
handleEdit
()
{
const
_file
=
this
.
par
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录