提交 ca9d0719 编写于 作者: qq_53854309's avatar qq_53854309

图片功能基本实现

上级 7fee76cd
...@@ -5,7 +5,9 @@ import com.hao.digitalsignature.encryption.AES1; ...@@ -5,7 +5,9 @@ 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.DownloadMsg;
import com.hao.digitalsignature.encryption.RSAEncrypt; import com.hao.digitalsignature.encryption.RSAEncrypt;
import com.hao.digitalsignature.entity.Download;
import com.hao.digitalsignature.entity.Files; import com.hao.digitalsignature.entity.Files;
import com.hao.digitalsignature.mapper.DownloadMapper;
import com.hao.digitalsignature.mapper.FileMapper; import com.hao.digitalsignature.mapper.FileMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -30,6 +32,9 @@ public class FileDealController { ...@@ -30,6 +32,9 @@ public class FileDealController {
@Autowired @Autowired
private FileMapper fileMapper; private FileMapper fileMapper;
@Autowired
private DownloadMapper downloadMapper;
@RequestMapping(value = "upload") @RequestMapping(value = "upload")
public String upload(@RequestParam("file") MultipartFile pic) throws SocketException, IOException { public String upload(@RequestParam("file") MultipartFile pic) throws SocketException, IOException {
String newName = ""; String newName = "";
...@@ -135,6 +140,14 @@ public class FileDealController { ...@@ -135,6 +140,14 @@ public class FileDealController {
System.out.println("正确签名和时间戳"+dig1[i]); System.out.println("正确签名和时间戳"+dig1[i]);
//生成AES密钥 //生成AES密钥
String aesPassword =AESmiyao.getKey(); 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加密 //AES加密
String encryContent= AES1.encryptAES(files.getDig().split(";")[2],aesPassword); String encryContent= AES1.encryptAES(files.getDig().split(";")[2],aesPassword);
//对称加密后的签名 //对称加密后的签名
...@@ -156,7 +169,7 @@ public class FileDealController { ...@@ -156,7 +169,7 @@ public class FileDealController {
String rsaDef=RSAEncrypt.RSAde(rsaEnf); String rsaDef=RSAEncrypt.RSAde(rsaEnf);
String rsaDes=RSAEncrypt.RSAde(rsaEns); String rsaDes=RSAEncrypt.RSAde(rsaEns);
String recRes=rsaDef+rsaDes; String recRes=rsaDef+rsaDes;
System.out.println('6');
DownloadMsg.downloadByStringContent(request, response, fileName.split("\\.")[0], recRes); DownloadMsg.downloadByStringContent(request, response, fileName.split("\\.")[0], recRes);
}catch (Exception e) { }catch (Exception e) {
......
package com.hao.digitalsignature.controller; 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.encryption.DSASign;
import com.hao.digitalsignature.entity.Download;
import com.hao.digitalsignature.entity.User; import com.hao.digitalsignature.entity.User;
import com.hao.digitalsignature.mapper.DownloadMapper;
import com.hao.digitalsignature.mapper.UserMapper; import com.hao.digitalsignature.mapper.UserMapper;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,29 +28,10 @@ public class FilesController { ...@@ -24,29 +28,10 @@ public class FilesController {
@Autowired @Autowired
private FileMapper fileMapper; private FileMapper fileMapper;
// @PostMapping("/upload")
// public String up(String name, MultipartFile photo, HttpServletRequest request) throws IOException{ @Autowired
// //自定文件名 private DownloadMapper downloadMapper;
// 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);
// }
@PutMapping("/file/update") @PutMapping("/file/update")
public String update(int id,String name){ public String update(int id,String name){
Files file = fileMapper.selectById(id); Files file = fileMapper.selectById(id);
...@@ -89,14 +74,45 @@ public class FilesController { ...@@ -89,14 +74,45 @@ public class FilesController {
System.out.println(file); System.out.println(file);
if(file.getCreatetime().equals( str[4])){ if(file.getCreatetime().equals( str[4])){
System.out.println("success"); 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 { }else {
System.out.println("failed"); System.out.println("failed");
} }
// str[3];
return "0"; 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") @GetMapping("/file/findAll")
public List<Files> find(){ public List<Files> find(){
......
...@@ -331,9 +331,10 @@ public class RSAEncrypt { ...@@ -331,9 +331,10 @@ public class RSAEncrypt {
} }
return stringBuilder.toString(); return stringBuilder.toString();
} }
//解密
public static String RSAde(byte[] cipherData) throws Exception { public static String RSAde(byte[] cipherData) throws Exception {
String publicPath = "C:\\Users\\w10"; //公匙存放位置 String publicPath = "C:\\Users\\10908"; //公匙存放位置
String privatePath = "C:\\Users\\w10"; //私匙存放位置 String privatePath = "C:\\Users\\10908"; //私匙存放位置
Base64 base64 = new Base64(); Base64 base64 = new Base64();
String cipher = new String(base64.encode(cipherData)); String cipher = new String(base64.encode(cipherData));
// 私钥解密过程 // 私钥解密过程
...@@ -343,9 +344,10 @@ public class RSAEncrypt { ...@@ -343,9 +344,10 @@ public class RSAEncrypt {
return restr; return restr;
} }
//加密
public static byte[] RSAen(String key) throws Exception { public static byte[] RSAen(String key) throws Exception {
String publicPath = "C:\\Users\\w10"; //公匙存放位置 String publicPath = "C:\\Users\\10908"; //公匙存放位置
String privatePath = "C:\\Users\\w10"; //私匙存放位置 String privatePath = "C:\\Users\\10908"; //私匙存放位置
Base64 base64 = new Base64(); Base64 base64 = new Base64();
String signKey = key; String signKey = key;
// 公钥加密过程 // 公钥加密过程
......
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 + '\'' +
'}';
}
}
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);
}
...@@ -4,6 +4,8 @@ spring.devtools.restart.additional-paths=src/main/java ...@@ -4,6 +4,8 @@ spring.devtools.restart.additional-paths=src/main/java
server.port=8081 server.port=8081
#ϴļС #ϴļС
logging.logback.rollingpolicy.max-file-size=10MB logging.logback.rollingpolicy.max-file-size=10MB
spring.servlet.multipart.max-file-size = 10MB
spring.servlet.multipart.max-request-size = 100MB
#swagger #swagger
spring.mvc.pathmatch.matching-strategy=ant_path_matcher spring.mvc.pathmatch.matching-strategy=ant_path_matcher
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
:on-remove="handleRemove" :on-remove="handleRemove"
:on-success="handlePicturePreview" :on-success="handlePicturePreview"
:http-request="uploadFile" :http-request="uploadFile"
:before-upload="beforeAvatarUpload"
> >
<i slot="default" class="el-icon-plus"></i> <i slot="default" class="el-icon-plus"></i>
<div slot="file" slot-scope="{file}"> <div slot="file" slot-scope="{file}">
...@@ -97,26 +98,24 @@ ...@@ -97,26 +98,24 @@
:src="file.url" alt="" :src="file.url" alt=""
> >
<span class="el-upload-list__item-actions"> <span class="el-upload-list__item-actions">
<span <span
class="el-upload-list__item-preview" class="el-upload-list__item-preview"
@click="handlePictureCardPreview(file)" @click="handlePictureCardPreview(file)"
> >
<i class="el-icon-zoom-in"></i> <i class="el-icon-zoom-in"></i>
</span> </span>
<span <span
v-if="!disabled" v-if="!disabled"
class="el-upload-list__item-delete" class="el-upload-list__item-delete"
@click="clearFiles()" @click="clearFiles()"
> >
<i class="el-icon-delete"></i> <i class="el-icon-delete"></i>
</span> </span>
</span> </span>
</div> </div>
</el-upload> </el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="handleEdit()">立即创建</el-button> <el-button type="primary" @click="handleEdit()">立即创建</el-button>
...@@ -124,6 +123,34 @@ ...@@ -124,6 +123,34 @@
</el-form-item> </el-form-item>
</el-form>. </el-form>.
</el-dialog> </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="handleEncryptionDig()">立即解密</el-button>
<el-button @click="dialogFormVisible2 = false,resetDig()">取消</el-button>
</el-form-item>
</el-form>.
</el-dialog>
</div> </div>
<el-table :data="filelist.slice((currentPage-1)*PageSize,currentPage*PageSize)" stripe style="width: 100%" :model="formData"> <el-table :data="filelist.slice((currentPage-1)*PageSize,currentPage*PageSize)" stripe style="width: 100%" :model="formData">
...@@ -137,14 +164,15 @@ ...@@ -137,14 +164,15 @@
</el-table-column> </el-table-column>
<el-table-column label="图片" align="center"> <el-table-column label="图片" align="center">
<div slot-scope="scope"> <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> </div>
</el-table-column> </el-table-column>
<el-table-column prop="createtime" label="创建时间"> <el-table-column prop="createtime" label="创建时间">
</el-table-column> </el-table-column>
<el-table-column label="功能" width="180"> <el-table-column label="功能" width="300">
<div slot-scope="scope" style="display: flex;justify-content: space-around"> <div slot-scope="scope" style="display: flex;justify-content: space-around">
<el-button type="primary" size="mini" @click="handleDownload(scope.row)">下载</el-button> <el-button type="primary" size="mini" @click="handleDownload(scope.row)">下载</el-button>
<el-upload <el-upload
class="upload-demo" class="upload-demo"
action="#" action="#"
...@@ -153,10 +181,12 @@ ...@@ -153,10 +181,12 @@
:show-file-list="false" :show-file-list="false"
accept="text/plain" accept="text/plain"
:limit="1" :limit="1"
:file-list="verifyList"> :file-list="verifyList"
<el-button size="small" type="primary">验证</el-button> ref="myVerify"
>
<el-button size="small" type="primary">验证时间戳</el-button>
</el-upload> </el-upload>
<el-button type="primary" size="mini" @click="handleDig(scope.row)">解密签名</el-button>
</div> </div>
</el-table-column> </el-table-column>
<el-empty description="暂无信息"></el-empty> <el-empty description="暂无信息"></el-empty>
...@@ -185,12 +215,17 @@ ...@@ -185,12 +215,17 @@
el: '#app', el: '#app',
data() { data() {
return { return {
rname:'',
par:'', par:'',
AES:'',
dig:'',
filelist: [], filelist: [],
digList:[],
verify:{}, verify:{},
verifyList:[], verifyList:[],
formData: {}, formData: {},
dialogFormVisible:false, dialogFormVisible:false,
dialogFormVisible2:false,
dialogFormVisible4Edit: false, dialogFormVisible4Edit: false,
dialogImageUrl:'', dialogImageUrl:'',
dialogVisible:false, dialogVisible:false,
...@@ -205,6 +240,8 @@ ...@@ -205,6 +240,8 @@
PageSize:3, PageSize:3,
rules: { rules: {
picture_name: [{ required: true, message: '请输入图片名称', trigger: 'blur' }], 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' }] picture:[{ required: true, message: '请上传图片', trigger: 'blur' }]
}, },
} }
...@@ -222,6 +259,7 @@ ...@@ -222,6 +259,7 @@
// 改变默认的页数 // 改变默认的页数
this.currentPage=val this.currentPage=val
}, },
handleOpen(key, keyPath) { handleOpen(key, keyPath) {
console.log(key, keyPath); console.log(key, keyPath);
...@@ -231,22 +269,38 @@ ...@@ -231,22 +269,38 @@
}, },
handlePicturePreview(file) { handlePicturePreview(file) {
console.log(file) console.log(file)
console.log(6)
this.par=file.raw; this.par=file.raw;
const isLt2M = file.size / 1024 / 1024 < 10;
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 10MB!');
this.clearFiles();
return isLt2M;
}
}, },
handlePreview(file) { handlePreview(file) {
console.log(file); console.log(file);
}, },
handleRemove(file) {
console.log(file)
},
clearFiles () { clearFiles () {
this.$refs['mYupload'].clearFiles(); this.$refs['mYupload'].clearFiles();
}, },
clearDig () {
this.$refs['myDig'].clearFiles();
},
handlePictureCardPreview(file) { handlePictureCardPreview(file) {
this.dialogImageUrl = file.url; this.dialogImageUrl = file.url;
this.dialogVisible = true; this.dialogVisible = true;
}, },
handlePictureCardPreviewTable(file) {
this.dialogImageUrl =window.document.location.href+'./img/'+file.picture_realname+'.'+file.picture_type;
this.dialogVisible = true;
},
handleDownload(file) { handleDownload(file) {
let f =file.picture_realname+"."+file.picture_type let f =file.picture_realname+"."+file.picture_type
axios.post("/file/download",f,).then((result)=>{ axios.post("/file/download",f,).then((result)=>{
...@@ -386,9 +440,18 @@ ...@@ -386,9 +440,18 @@
//重置表单 //重置表单
resetForm() { resetForm() {
this.formData = {}; this.formData = {};
//this.$refs['form'].clearValidate(); //this.$refs['myDig'].clearValidate();
this.$nextTick(() => {
this.$refs.mYupload.clearFiles()
})
},
//重置解密
resetDig() {
this.formData = {};
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.forms.clearValidate() this.$refs.myDig.clearFiles()
}) })
}, },
//弹出添加窗口 //弹出添加窗口
...@@ -396,11 +459,20 @@ ...@@ -396,11 +459,20 @@
this.resetForm(); this.resetForm();
this.dialogFormVisible = true; this.dialogFormVisible = true;
}, },
uploadDig(file){
this.dig=file.raw;
},
handleDig(file) {
this.rname=file.picture_realname;
this.resetDig();
this.dialogFormVisible2 = true;
},
handleVerify() { handleVerify() {
this.resetForm(); this.resetForm();
this.dialogFormVisible4Edit = true; this.dialogFormVisible4Edit = true;
}, },
openFile(file,name) { openFile(file,name) {
let this_vue=this
//验证的文件 //验证的文件
console.log(name.picture_name) console.log(name.picture_name)
var reader = new FileReader(); var reader = new FileReader();
...@@ -411,11 +483,52 @@ ...@@ -411,11 +483,52 @@
var p= name.picture_id+';'+ reader.result var p= name.picture_id+';'+ reader.result
axios.post("/file/verify", p,{headers: { 'Content-Type': 'application/json','data': 'JSON.stringify(Data)'}}).then((res) => { 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); 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() { handleEdit() {
const _file = this.par; const _file = this.par;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册