提交 de1616bc 编写于 作者: H hml

用户

上级 2031f617
...@@ -28,7 +28,8 @@ public class FilesController { ...@@ -28,7 +28,8 @@ public class FilesController {
@Autowired @Autowired
private FileMapper fileMapper; private FileMapper fileMapper;
@Autowired
private UserMapper userMapper;
@Autowired @Autowired
private DownloadMapper downloadMapper; private DownloadMapper downloadMapper;
...@@ -52,9 +53,13 @@ public class FilesController { ...@@ -52,9 +53,13 @@ public class FilesController {
DSASign dsa = new DSASign(); DSASign dsa = new DSASign();
dsa.initKeys(); dsa.initKeys();
//要签名的数据,传入AES加密后的内容 //要签名的数据,传入AES加密后的内容
String message = file.getPicture_realname(); String message =file.getPicture_user() + file.getPicture_realname();
System.out.println("签名的数据:"+message); //获取上传用户的dsa密钥
BigInteger sig[] = dsa.signature(message.getBytes()); QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.eq("email", file.getPicture_user());
User user = userMapper.selectOne(wrapper);
BigInteger sig[] = dsa.signature(message.getBytes(),user.getDsakey());
String dig=sig[0]+";"+sig[1]+";"+dsa._hashInZq(message.getBytes()); String dig=sig[0]+";"+sig[1]+";"+dsa._hashInZq(message.getBytes());
file.setDig(dig); file.setDig(dig);
int i = fileMapper.insert(file); int i = fileMapper.insert(file);
...@@ -90,6 +95,7 @@ public class FilesController { ...@@ -90,6 +95,7 @@ public class FilesController {
for(int i =0;i<strs.length;i++) for(int i =0;i<strs.length;i++)
System.out.println(strs[i]); System.out.println(strs[i]);
try { try {
//得到aes解密后的消息摘要
String encryContent= AES1.decryptAES(strs[2],strs[4]); String encryContent= AES1.decryptAES(strs[2],strs[4]);
strs[2]=encryContent; strs[2]=encryContent;
String newStr =new String(); String newStr =new String();
...@@ -101,19 +107,28 @@ public class FilesController { ...@@ -101,19 +107,28 @@ public class FilesController {
QueryWrapper<Files> wrapper = new QueryWrapper<>(); QueryWrapper<Files> wrapper = new QueryWrapper<>();
wrapper.eq("picture_realname", strs[5]); wrapper.eq("picture_realname", strs[5]);
Files files = fileMapper.selectOne(wrapper); Files files = fileMapper.selectOne(wrapper);
System.out.println(files.getDig());
System.out.println(newStr); //获取上传用户的dsa密钥
if(files.getDig().equals(newStr)){ QueryWrapper<User> wrappers = new QueryWrapper<>();
return "success"; wrappers.eq("email", files.getPicture_user());
}else { User user = userMapper.selectOne(wrappers);
return "failed"; DSASign dsaSign=new DSASign();
} System.out.println(dsaSign.verify(newStr,user.getDsakey()));
if(dsaSign.verify(newStr,user.getDsakey())){
return "success";
}else {
return "failed";
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return "error"; return "error";
} }
@GetMapping("/file/findAll") @GetMapping("/file/findAll")
public List<Files> find(){ public List<Files> find(){
return fileMapper.selectList(null); return fileMapper.selectList(null);
......
package com.hao.digitalsignature.controller; 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.DSASign;
import com.hao.digitalsignature.entity.User; import com.hao.digitalsignature.entity.User;
import com.hao.digitalsignature.mapper.UserMapper; import com.hao.digitalsignature.mapper.UserMapper;
...@@ -41,6 +42,9 @@ public class UserController { ...@@ -41,6 +42,9 @@ public class UserController {
return "exist"; return "exist";
} }
System.out.println("不存在"); System.out.println("不存在");
DSASign dsaSign=new DSASign();
String dsakey = dsaSign.initKeys();
user.setDsakey(dsakey);
int i = userMapper.insert(user); int i = userMapper.insert(user);
if (i>0) if (i>0)
return "success"; return "success";
......
...@@ -4,6 +4,7 @@ import java.math.BigInteger; ...@@ -4,6 +4,7 @@ import java.math.BigInteger;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.sql.Array;
import java.sql.SQLOutput; import java.sql.SQLOutput;
import com.hao.digitalsignature.encryption.RSAEncrypt; import com.hao.digitalsignature.encryption.RSAEncrypt;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
...@@ -36,7 +37,7 @@ public class DSASign { ...@@ -36,7 +37,7 @@ public class DSASign {
return null; return null;
} }
//生成公钥私钥 //生成公钥私钥
public void initKeys(){ public String initKeys(){
q = new BigInteger(160, 100, new SecureRandom()); q = new BigInteger(160, 100, new SecureRandom());
// 判定100%为素数 // 判定100%为素数
do { do {
...@@ -49,14 +50,24 @@ public class DSASign { ...@@ -49,14 +50,24 @@ public class DSASign {
g = h.modPow(p.subtract(BigInteger.ONE).divide(q), p); g = h.modPow(p.subtract(BigInteger.ONE).divide(q), p);
x = _randomInZq(); x = _randomInZq();
y = g.modPow(x, p); y = g.modPow(x, p);
String dsakey = q+";"+p+";"+g+";"+x+";"+y;
System.out.println("p : " + p); System.out.println("p : " + p);
System.out.println("q : " + q); System.out.println("q : " + q);
System.out.println("g : " + g); System.out.println("g : " + g);
System.out.println("发送方私钥x : " + x); System.out.println("发送方私钥x : " + x);
System.out.println("发送方公钥y : " + y); System.out.println("发送方公钥y : " + y);
return dsakey;
} }
//产生签名 //产生签名
public BigInteger[] signature(byte m[]){ public BigInteger[] signature(byte m[] ,String dsakey){
String str[] = dsakey.split(";");
BigInteger q= new BigInteger(str[0]);
BigInteger p= new BigInteger(str[1]);
BigInteger g= new BigInteger(str[2]);
BigInteger x= new BigInteger(str[3]);
BigInteger k = _randomInZq(); BigInteger k = _randomInZq();
BigInteger sig[] = new BigInteger[2]; BigInteger sig[] = new BigInteger[2];
//得到r //得到r
...@@ -67,45 +78,63 @@ public class DSASign { ...@@ -67,45 +78,63 @@ public class DSASign {
return sig; return sig;
} }
//验证 //验证
public boolean verify(byte m[], BigInteger sig[]){ public boolean verify( String strsig,String key){
String[] str = strsig.split(";");
if(str[2].equals("null")){
System.out.println("false");
return false;
}
BigInteger[] sig = new BigInteger[2];
sig[0]=new BigInteger(str[0]);
sig[1]=new BigInteger(str[1]);
BigInteger Hm= new BigInteger(str[2]);
String strs[] = key.split(";");
BigInteger q= new BigInteger(strs[0]);
BigInteger p= new BigInteger(strs[1]);
BigInteger g= new BigInteger(strs[2]);
BigInteger y= new BigInteger(strs[4]);
BigInteger w = sig[1].modInverse(q); BigInteger w = sig[1].modInverse(q);
BigInteger u1 = _hashInZq(m).multiply(w).mod(q); BigInteger u1 = Hm.multiply(w).mod(q);
BigInteger u2 = sig[0].multiply(w).mod(q); BigInteger u2 = sig[0].multiply(w).mod(q);
BigInteger v = g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q); BigInteger v = g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q);
System.out.println("验证:");
System.out.println("v = " + v);
System.out.println("r = " + sig[0]);
return v.compareTo(sig[0]) == 0; return v.compareTo(sig[0]) == 0;
} }
public static void main(String args[]) throws Exception { // public static void main(String args[]) throws Exception {
String publicPath = "C:\\Users\\10908"; //公匙存放位置 // String publicPath = "C:\\Users\\10908"; //公匙存放位置
String privatePath = "C:\\Users\\10908"; //私匙存放位置 // String privatePath = "C:\\Users\\10908"; //私匙存放位置
BigInteger back[]=new BigInteger[2]; // BigInteger back[]=new BigInteger[2];
int j=0; // int j=0;
Base64 base64 = new Base64(); // Base64 base64 = new Base64();
DSASign dsa = new DSASign(); // DSASign dsa = new DSASign();
//
//生成公钥和私钥 // //生成公钥和私钥
dsa.initKeys(); // dsa.initKeys();
System.out.println(""); // System.out.println("");
//要签名的数据,传入AES加密后的内容 // //要签名的数据,传入AES加密后的内容
String message = "NUJCQkJEQjRCRDBFODMwRTJCODkyOTQ1N0Y4NkEyNzU="; // String message = "NUJCQkJEQjRCRDBFODMwRTJCODkyOTQ1N0Y4NkEyNzU=";
System.out.println("签名的数据:"+message); // System.out.println("签名的数据:"+message);
BigInteger sig[] = dsa.signature(message.getBytes()); // BigInteger sig[] = dsa.signature(message.getBytes(), );
//
//消息摘要 // //消息摘要
System.out.println("消息摘要:"+dsa._hashInZq(message.getBytes())+"\n"); // System.out.println("消息摘要:"+dsa._hashInZq(message.getBytes())+"\n");
//
//对消息摘要进行签名得到r和s,在使用RSA进行加密并发送 // //对消息摘要进行签名得到r和s,在使用RSA进行加密并发送
for (int i =0;i< sig.length;i++){ // for (int i =0;i< sig.length;i++){
System.out.println("签名:"+sig[i].toString()); // System.out.println("签名:"+sig[i].toString());
back[i]= new BigInteger(RSAEncrypt.RSAen(sig[i].toString())); // back[i]= new BigInteger(RSAEncrypt.RSAen(sig[i].toString()));
} // }
System.out.println("\n需要解密的信息:"+back[0]); // System.out.println("\n需要解密的信息:"+back[0]);
System.out.println(" "+back[1]); // System.out.println(" "+back[1]);
//
System.out.println("验证结果:" + dsa.verify(message.getBytes(),back) ); // System.out.println("验证结果:" + dsa.verify(message.getBytes(),back) );
} // }
} }
...@@ -333,8 +333,8 @@ public class RSAEncrypt { ...@@ -333,8 +333,8 @@ public class RSAEncrypt {
} }
//解密 //解密
public static String RSAde(byte[] cipherData) throws Exception { public static String RSAde(byte[] cipherData) throws Exception {
String publicPath = "C:\\Users\\10908"; //公匙存放位置 String publicPath = "C:\\Users\\w10"; //公匙存放位置
String privatePath = "C:\\Users\\10908"; //私匙存放位置 String privatePath = "C:\\Users\\w10"; //私匙存放位置
Base64 base64 = new Base64(); Base64 base64 = new Base64();
String cipher = new String(base64.encode(cipherData)); String cipher = new String(base64.encode(cipherData));
// 私钥解密过程 // 私钥解密过程
...@@ -346,8 +346,8 @@ public class RSAEncrypt { ...@@ -346,8 +346,8 @@ public class RSAEncrypt {
} }
//加密 //加密
public static byte[] RSAen(String key) throws Exception { public static byte[] RSAen(String key) throws Exception {
String publicPath = "C:\\Users\\10908"; //公匙存放位置 String publicPath = "C:\\Users\\w10"; //公匙存放位置
String privatePath = "C:\\Users\\10908"; //私匙存放位置 String privatePath = "C:\\Users\\w10"; //私匙存放位置
Base64 base64 = new Base64(); Base64 base64 = new Base64();
String signKey = key; String signKey = key;
// 公钥加密过程 // 公钥加密过程
......
...@@ -11,12 +11,12 @@ public class Files { ...@@ -11,12 +11,12 @@ public class Files {
private String picture_name; private String picture_name;
private String picture_type; private String picture_type;
@TableField(insertStrategy = FieldStrategy.IGNORED) @TableField(insertStrategy = FieldStrategy.IGNORED)
private Integer picture_user; private String picture_user;
private String createtime; private String createtime;
private String picture_realname; private String picture_realname;
private String dig; private String dig;
public Files(Integer picture_id, String picture_name, String picture_type, Integer picture_user, String createtime, String picture_realname, String dig) { public Files(Integer picture_id, String picture_name, String picture_type, String picture_user, String createtime, String picture_realname, String dig) {
this.picture_id = picture_id; this.picture_id = picture_id;
this.picture_name = picture_name; this.picture_name = picture_name;
this.picture_type = picture_type; this.picture_type = picture_type;
...@@ -50,11 +50,11 @@ public class Files { ...@@ -50,11 +50,11 @@ public class Files {
this.picture_type = picture_type; this.picture_type = picture_type;
} }
public Integer getPicture_user() { public String getPicture_user() {
return picture_user; return picture_user;
} }
public void setPicture_user(Integer picture_user) { public void setPicture_user(String picture_user) {
this.picture_user = picture_user; this.picture_user = picture_user;
} }
......
...@@ -20,13 +20,15 @@ public class User { ...@@ -20,13 +20,15 @@ public class User {
private String telephone; private String telephone;
@TableField(insertStrategy = FieldStrategy.IGNORED) @TableField(insertStrategy = FieldStrategy.IGNORED)
private String country; private String country;
private String dsakey;
@TableField(exist = false) @TableField(exist = false)
private List<Files> files; private List<Files> files;
@TableField(exist = false) @TableField(exist = false)
private String passwordAgain; private String passwordAgain;
public User(Integer user_id, String password, String email, String user_name, String realname, String telephone, String country) { public User(Integer user_id, String password, String email, String user_name, String realname, String telephone, String country, String dsakey) {
this.user_id = user_id; this.user_id = user_id;
this.password = password; this.password = password;
this.email = email; this.email = email;
...@@ -34,6 +36,7 @@ public class User { ...@@ -34,6 +36,7 @@ public class User {
this.realname = realname; this.realname = realname;
this.telephone = telephone; this.telephone = telephone;
this.country = country; this.country = country;
this.dsakey = dsakey;
} }
public Integer getUser_id() { public Integer getUser_id() {
...@@ -108,6 +111,14 @@ public class User { ...@@ -108,6 +111,14 @@ public class User {
this.passwordAgain = passwordAgain; this.passwordAgain = passwordAgain;
} }
public String getDsakey() {
return dsakey;
}
public void setDsakey(String dsakey) {
this.dsakey = dsakey;
}
@Override @Override
public String toString() { public String toString() {
return "User{" + return "User{" +
...@@ -118,6 +129,7 @@ public class User { ...@@ -118,6 +129,7 @@ public class User {
", realname='" + realname + '\'' + ", realname='" + realname + '\'' +
", telephone='" + telephone + '\'' + ", telephone='" + telephone + '\'' +
", country='" + country + '\'' + ", country='" + country + '\'' +
", dsakey='" + dsakey + '\'' +
", files=" + files + ", files=" + files +
", passwordAgain='" + passwordAgain + '\'' + ", passwordAgain='" + passwordAgain + '\'' +
'}'; '}';
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<title>Document</title> <title>Document</title>
<!-- 引入样式 --> <!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<link rel="stylesheet" href="css/Reg.css"> <link rel="stylesheet" href="css/Reg.css">
</head> </head>
<body> <body>
<div id="app"> <div id="app">
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
</el-form> </el-form>
</div> </div>
</body> </body>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js"></script>
<script src="./js/axios-0.27.2.js"></script> <script src="./js/axios-0.27.2.js"></script>
<script type="text/javascript" src="./js/jquery-3.6.0.js"></script> <script type="text/javascript" src="./js/jquery-3.6.0.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.1/dist/vue.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.1/dist/vue.js"></script>
......
...@@ -13,22 +13,29 @@ ...@@ -13,22 +13,29 @@
<div id="app"> <div id="app">
<div style="text-align: center;"><h2>注册账号</h2></div> <div style="text-align: center;"><h2>注册账号</h2></div>
<br> <br>
<el-form ref="forms" :model="form" label-width="80px" :rules="rules" label-position="top" >
<el-form ref="forms" :model="form" label-width="80px" :rules="rules" label-position="top" autocomplete="off">
<el-form-item :rules="rules.user_name" prop="user_name"> <el-form-item :rules="rules.user_name" prop="user_name">
<label class="el-form-item__label efi" >用户名</label> <label class="el-form-item__label efi" >用户名</label>
<el-input v-model="form.user_name" placeholder="请输入用户名"></el-input> <el-input v-model="form.user_name" autocomplete ="off" placeholder="请输入用户名"></el-input>
</el-form-item> </el-form-item>
<el-form-item :rules="rules.email" prop="email"> <el-form-item :rules="rules.email" prop="email">
<label class="el-form-item__label efi" >邮箱</label> <label class="el-form-item__label efi" >邮箱</label>
<el-input v-model="form.email" ref="email" placeholder="请输入邮箱" type="email"></el-input> <!-- <input type="email" style="display: none">-->
<el-input v-model="form.email" ref="email" auto-complete="new-email" placeholder="请输入邮箱" type="email"></el-input>
</el-form-item> </el-form-item>
<div style="display:block;opacity: 0;width:0px;height:0px;overflow: hidden">
<input type="email" name="username" autocomplete="off"/>
<input type="password" name="password" autocomplete="off" readonly/>
</div>
<el-form-item :rules="rules.password" prop="password"> <el-form-item :rules="rules.password" prop="password">
<label class="el-form-item__label efi" >密码</label> <label class="el-form-item__label efi" >密码</label>
<el-input v-model="form.password" placeholder="请输入密码" show-password type="password"></el-input> <!-- <input type="password" style="display: none">-->
<el-input class="pwd" v-model="form.password" auto-complete="new-password" placeholder="请输入密码" type="password"></el-input>
</el-form-item> </el-form-item>
<el-form-item :rules="rules.passwordAgain" prop="passwordAgain"> <el-form-item :rules="rules.passwordAgain" prop="passwordAgain">
<label class="el-form-item__label efi" >确认密码</label> <label class="el-form-item__label efi" >确认密码</label>
<el-input v-model="form.passwordAgain" ref="pwda" placeholder="请再次输入密码" show-password type="password"></el-input> <el-input class="pwd" v-model="form.passwordAgain" autocomplete ="off" ref="pwda" placeholder="请再次输入密码" type="text"></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" id="btn" @click="onSubmit">注册</el-button> <el-button type="primary" id="btn" @click="onSubmit">注册</el-button>
...@@ -36,9 +43,11 @@ ...@@ -36,9 +43,11 @@
<div class="sw"> <div class="sw">
已有账号,<a href="Login.html">去登陆</a> 已有账号,<a href="Login.html">去登陆</a>
</div> </div>
</el-form> </el-form>
</div> </div>
</body> </body>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js"></script>
<script src="./js/axios-0.27.2.js"></script> <script src="./js/axios-0.27.2.js"></script>
<script type="text/javascript" src="./js/jquery-3.6.0.js"></script> <script type="text/javascript" src="./js/jquery-3.6.0.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.1/dist/vue.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.1/dist/vue.js"></script>
......
...@@ -26,4 +26,8 @@ body{ ...@@ -26,4 +26,8 @@ body{
} }
.sw{ .sw{
text-align: center; text-align: center;
}
.pwd{
text-security:disc;
-webkit-text-security:disc;
} }
\ No newline at end of file
...@@ -54,3 +54,23 @@ body>.el-container { ...@@ -54,3 +54,23 @@ body>.el-container {
.el-breadcrumb { .el-breadcrumb {
margin-bottom: 20px; margin-bottom: 20px;
} }
.nav{
display: inline-block;
position: absolute;
right: 0;
margin-right: 50px;
font-size: 16px;
text-decoration: none;
font-weight: normal;
color: white;
}
.nav a{
text-decoration: none;
font-size: 16px;
text-decoration: none;
font-weight: normal;
color: white;
}
.nav a:hover{
color: orange;
}
...@@ -14,9 +14,7 @@ ...@@ -14,9 +14,7 @@
<link rel="stylesheet" href="./css/index.css"> <link rel="stylesheet" href="./css/index.css">
<link rel="stylesheet" href="./css/upload.css"> <link rel="stylesheet" href="./css/upload.css">
<title>Document</title> <title>Document</title>
<style>
</style>
</head> </head>
...@@ -26,8 +24,11 @@ ...@@ -26,8 +24,11 @@
<el-container> <el-container>
<el-header> <el-header>
数字图像保护系统 数字图像保护系统
<a href="Login.html" style="float: right">登录</a> <div class="nav">
<a href="Reg.html" style="float: right">注册</a> <a href="Login.html" class="rl" >登录</a>
<span> / </span>
<a href="Reg.html" class="rl" >注册</a>
</div>
</el-header> </el-header>
<el-container> <el-container>
...@@ -89,10 +90,7 @@ ...@@ -89,10 +90,7 @@
accept="image/png, image/jpeg" accept="image/png, image/jpeg"
ref="mYupload" ref="mYupload"
:on-change="handlePicturePreview" :on-change="handlePicturePreview"
:on-remove="handleRemove"
:on-success="handlePicturePreview" :on-success="handlePicturePreview"
: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}">
...@@ -163,7 +161,7 @@ ...@@ -163,7 +161,7 @@
</el-table-column> </el-table-column>
<el-table-column prop="picture_type" label="类型" width="50"> <el-table-column prop="picture_type" label="类型" width="50">
</el-table-column> </el-table-column>
<el-table-column prop="picture_user" label="用户" width="100"> <el-table-column prop="picture_user" label="用户" width="120">
</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">
...@@ -210,339 +208,10 @@ ...@@ -210,339 +208,10 @@
</el-container> </el-container>
</div> </div>
</body> </body>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js"></script>
<script src="./js/axios-0.27.2.js"></script> <script src="./js/axios-0.27.2.js"></script>
<script type="text/javascript" src="./js/jquery-3.6.0.js"></script> <script type="text/javascript" src="./js/jquery-3.6.0.js"></script>
<script> <script src="js/javascript/index.js"></script>
new Vue({
el: '#app',
data() {
return {
rname:'',
par:'',
AES:'',
dig:'',
filelist: [],
digList:[],
verify:{},
verifyList:[],
formData: {},
dialogFormVisible:false,
dialogFormVisible2:false,
dialogFormVisible4Edit: false,
dialogImageUrl:'',
dialogVisible:false,
disabled:false,
// 默认显示第几页
currentPage:1,
// 总条数,根据接口获取数据长度(注意:这里不能为空)
totalCount:1,
// 个数选择器(可修改)
pageSizes:[3,5,10],
// 默认每页显示的条数(可修改)
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' }]
},
}
},
methods: {
// 每页显示的条数
handleSizeChange(val) {
// 改变每页显示的条数
this.PageSize=val
// 注意:在改变每页显示的条数时,要将页码显示到第一页
this.currentPage=1
},
// 显示第几页
handleCurrentChange(val) {
// 改变默认的页数
this.currentPage=val
},
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
},
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);
},
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)=>{
var url = (window.document.location.href+"img/"+result.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 + ".png");
} 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)
}
});
})
axios.post("/file/downloadMsg",f,).then((res)=>{
console.log(res)
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
convertUrlToBase64(url) {
return new Promise(function (resolve, reject) {
var img = new Image();
//设置图片跨越,没有跨越cavas会被污染无法画出
img.crossOrigin = "Anonymous";
img.src = url;
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var ext = img.src
.substring(img.src.lastIndexOf(".") + 1)
.toLowerCase();
//转换为base64
var dataURL = canvas.toDataURL("image/" + ext);
var base64 = {
dataURL: dataURL,
type: "image/" + ext,
ext: ext
};
resolve(base64);
};
});
},
// base64转换为blob流
convertBase64UrlToBlob(base64) {
var parts = base64.dataURL.split(";base64,");
var contentType = parts[0].split(":")[1];
var raw = window.atob(parts[1]);
var rawLength = raw.length;
var uInt8Array = new Uint8Array(rawLength);
for (var i = 0; i < rawLength; i++) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {
type: contentType
});
},
// 判断浏览器
myBrowser() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
if (userAgent.indexOf("OPR") > -1) {
return "Opera";
} //判断是否Opera浏览器 OPR/43.0.2442.991
if (userAgent.indexOf("Firefox") > -1) {
return "FF";
} //判断是否Firefox浏览器 Firefox/51.0
if (userAgent.indexOf("Trident") > -1) {
return "IE";
} //判断是否IE浏览器 Trident/7.0; rv:11.0
if (userAgent.indexOf("Edge") > -1) {
return "Edge";
} //判断是否Edge浏览器 Edge/14.14393
if (userAgent.indexOf("Chrome") > -1) {
return "Chrome";
} // Chrome/56.0.2924.87
if (userAgent.indexOf("Safari") > -1) {
return "Safari";
} //判断是否Safari浏览器 AppleWebKit/534.57.2 Version/5.1.7 Safari/534.57.2
},
init(){
axios.get("/file/findAll", this.formData, ).then((result) => {
this.filelist = result.data
this.totalCount=result.data.length
})
},
//重置表单
resetForm() {
this.formData = {};
//this.$refs['myDig'].clearValidate();
this.$nextTick(() => {
this.$refs.mYupload.clearFiles()
})
},
//重置解密
resetDig() {
this.formData = {};
this.$nextTick(() => {
this.$refs.myDig.clearFiles()
})
},
//弹出添加窗口
handleCreate() {
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();
reader.onload = function () {
if (reader.result) {
//打印文件内容
console.log(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) => {
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;
// 通过 FormData 对象上传文件
var formData = new FormData();
formData.append("file", _file);
axios.post("/file/upload",formData).then((res)=>{
console.log(res.data)
this.formData.picture_realname=res.data.split(".")[0]
console.log(this.picture_realname)
this.formData.picture_type=res.data.split(".")[1]
console.log(this.formData.picture_type)
console.log(this.formData)
axios.post("/file/save", this.formData).then((result) => {
console.log(result)
console.log(this.formData )
this.resetForm();
this.dialogFormVisible = false;
this.clearFiles()
});
}).then(function (){
this.init()
})
},
},
mounted() {
this.init();
}
})
</script>
</html> </html>
var b=document.querySelector("body") var b=document.querySelector("body")
b.style.height=document.documentElement.clientHeight+'px' b.style.height=document.documentElement.clientHeight+'px'
new Vue({ new Vue({
el: '#app', el: '#app',
data() { data() {
...@@ -30,7 +31,10 @@ new Vue({ ...@@ -30,7 +31,10 @@ new Vue({
that.$refs.psw.focus(); that.$refs.psw.focus();
}); });
}else{ }else{
window.location.href="index.html" Cookies.set('email', this.form.email, { expires: 1 });
let lo = window.location.href.indexOf("/Login.html")
let newUrl =window.location.href.substring(0,lo)
window.location.href= newUrl
} }
}) })
} }
......
var b=document.querySelector("body") var b=document.querySelector("body")
b.style.height=document.documentElement.clientHeight +'px' b.style.height=document.documentElement.clientHeight +'px'
new Vue({ new Vue({
el: '#app', el: '#app',
data() { data() {
...@@ -15,6 +16,7 @@ new Vue({ ...@@ -15,6 +16,7 @@ new Vue({
} }
}, },
methods: { methods: {
onSubmit() { onSubmit() {
const that = this const that = this
if(this.form.password==this.form.passwordAgain){ if(this.form.password==this.form.passwordAgain){
...@@ -23,14 +25,13 @@ new Vue({ ...@@ -23,14 +25,13 @@ new Vue({
this.$alert('邮箱已被使用,请重新输入','警告', { this.$alert('邮箱已被使用,请重新输入','警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
}).then(function () { }).then(function () {
//聚焦再次输入密码
that.$refs.email.focus(); that.$refs.email.focus();
}); });
}else{ }else{
this.$alert('注册成功','恭喜', { this.$alert('注册成功','恭喜', {
confirmButtonText: '确定', confirmButtonText: '确定',
}).then(function () { }).then(function () {
window.location.href="index.html" window.location.href="Login.html"
}); });
} }
}) })
......
new Vue({
el: '#app',
data() {
return {
rname:'',
par:'',
AES:'',
dig:'',
filelist: [],
digList:[],
verify:{},
verifyList:[],
formData: {},
dialogFormVisible:false,
dialogFormVisible2:false,
dialogFormVisible4Edit: false,
dialogImageUrl:'',
dialogVisible:false,
disabled:false,
// 默认显示第几页
currentPage:1,
// 总条数,根据接口获取数据长度(注意:这里不能为空)
totalCount:1,
// 个数选择器(可修改)
pageSizes:[3,5,10],
// 默认每页显示的条数(可修改)
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' }]
},
}
},
methods: {
// 每页显示的条数
handleSizeChange(val) {
// 改变每页显示的条数
this.PageSize=val
// 注意:在改变每页显示的条数时,要将页码显示到第一页
this.currentPage=1
},
// 显示第几页
handleCurrentChange(val) {
// 改变默认的页数
this.currentPage=val
},
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
},
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);
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
this.dialogVisible = true;
},
handlePictureCardPreviewTable(file) {
this.dialogImageUrl =window.document.location.href+'./img/'+file.picture_realname+'.'+file.picture_type;
console.log(this.dialogImageUrl)
this.dialogVisible = true;
},
handleDownload(file) {
let f =file.picture_realname+"."+file.picture_type
axios.post("/file/download",f,).then((result)=>{
var url = (window.document.location.href+"img/"+result.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 + ".png");
} 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)
}
});
})
axios.post("/file/downloadMsg",f,).then((res)=>{
console.log(res)
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
convertUrlToBase64(url) {
return new Promise(function (resolve, reject) {
var img = new Image();
//设置图片跨越,没有跨越cavas会被污染无法画出
img.crossOrigin = "Anonymous";
img.src = url;
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var ext = img.src
.substring(img.src.lastIndexOf(".") + 1)
.toLowerCase();
//转换为base64
var dataURL = canvas.toDataURL("image/" + ext);
var base64 = {
dataURL: dataURL,
type: "image/" + ext,
ext: ext
};
resolve(base64);
};
});
},
// base64转换为blob流
convertBase64UrlToBlob(base64) {
var parts = base64.dataURL.split(";base64,");
var contentType = parts[0].split(":")[1];
var raw = window.atob(parts[1]);
var rawLength = raw.length;
var uInt8Array = new Uint8Array(rawLength);
for (var i = 0; i < rawLength; i++) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {
type: contentType
});
},
// 判断浏览器
myBrowser() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
if (userAgent.indexOf("OPR") > -1) {
return "Opera";
} //判断是否Opera浏览器 OPR/43.0.2442.991
if (userAgent.indexOf("Firefox") > -1) {
return "FF";
} //判断是否Firefox浏览器 Firefox/51.0
if (userAgent.indexOf("Trident") > -1) {
return "IE";
} //判断是否IE浏览器 Trident/7.0; rv:11.0
if (userAgent.indexOf("Edge") > -1) {
return "Edge";
} //判断是否Edge浏览器 Edge/14.14393
if (userAgent.indexOf("Chrome") > -1) {
return "Chrome";
} // Chrome/56.0.2924.87
if (userAgent.indexOf("Safari") > -1) {
return "Safari";
} //判断是否Safari浏览器 AppleWebKit/534.57.2 Version/5.1.7 Safari/534.57.2
},
init(){
const that = this
axios.get("/file/findAll", this.formData, ).then((result) => {
that.filelist = result.data
that.totalCount=result.data.length
});
let nav =document.querySelector(".nav")
console.log(Cookies.get('email')==undefined)
if(Cookies.get('email')!=undefined){
nav.innerHTML =`欢迎您,<a href="#">${Cookies.get('email')}</a>
<a href="#" onclick="quit()">退出</a> `
}else{
nav.innerHTML = `<a href="Login.html" class="rl" >登录</a>
<span> / </span>
<a href="Reg.html" class="rl" >注册</a>`
}
},
quit(){
Cookies.remove('email');
this.init()
},
//重置表单
resetForm() {
this.formData = {};
//this.$refs['myDig'].clearValidate();
this.$nextTick(() => {
this.$refs.mYupload.clearFiles()
})
},
//重置解密
resetDig() {
this.digList = {};
this.$nextTick(() => {
this.$refs.myDig.clearFiles()
})
},
//重置验证
resetDig() {
this.verifyList = {};
this.$nextTick(() => {
this.$refs.myVerify.clearFiles()
})
},
//弹出添加窗口
handleCreate() {
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();
reader.onload = function () {
if (reader.result) {
//打印文件内容
console.log(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) => {
if(res.data!=0){
this_vue.$alert('AES密钥(请复制):'+res.data,'验证成功', {
confirmButtonText: '确定',
});
}else{
this_vue.$alert("请重新确认",'验证错误', {
confirmButtonText: '确定',
});
}
})
}
};
reader.readAsText(file.raw);
this.resetDig()
},
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() {
let that = this
if(this.ifLogin()) {
const _file = this.par;
// 通过 FormData 对象上传文件
var formData = new FormData();
formData.append("file", _file);
this.formData.picture_user= this.ifLogin();
console.log(this.formData)
axios.post("/file/upload", formData).then((res) => {
this.formData.picture_realname = res.data.split(".")[0]
this.formData.picture_type = res.data.split(".")[1]
axios.post("/file/save", this.formData).then((result) => {
this.resetForm();
this.dialogFormVisible = false;
this.clearFiles()
}).then(function () {
that.init()
});
})
}else {
this_vue.$alert('还未登录','警告', {
confirmButtonText: '确定',
});
}
},
ifLogin(){
if(Cookies.get('email')==undefined){
return false
}else {
return Cookies.get('email')
}
}
},
mounted() {
this.init();
window.quit=this.quit
}
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册