-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_ecdh.html
96 lines (75 loc) · 3.17 KB
/
demo_ecdh.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html>
<head>
<!-- 测试ECC加密,与后端的加密做对比 -->
<meta charset="utf-8" >
<title>ECC加密</title>
<!-- <link rel="stylesheet" type="text/css" href="./style.css"> -->
<script src= './bytesForms.js'></script>
<script src= './axlsign.js'></script>
<script src= './cryptoMgr.js'></script>
<link rel="stylesheet" type="text/css" href="common.css">
<script src= './common.js'></script>
</head>
<body>
<div id='header'>
<div style='display:inline;font-weight:600;'>Curve 25519 加密 - 模拟客户的网页端</div>
<div style='display:inline' id='status'></div>
<button class='btn' id='show_footer' style='display:inline; float:right; visibility:hidden; font-weight:600' onclick='reset_footer()'>⋀</button>
</div>
<div id='nav'>
<div class='navlink'></div>
</div>
<div id='main'>
<!-- 以下开始正文内容-->
<p>收到服务器的链接,@后面是base64公钥:</p>
<input type='text' id="URL" class='inputbox' style='background-color:aqua; min-height: 3rem;
white-space: pre-wrap; word-wrap: break-all; overflow:auto;'>
<br>
<h3>本地密钥</h3>
<button onclick="getMyEck()"><b>生成本地密钥!</b></button><br>
<p>私钥</p>
<div id="client-sk" class="outputbox">暂无</div>
<p>发给服务器的公钥</p>
<div id="client-pk" class="outputbox">暂无</div>
<br>
<button onclick="getShared()"><b>服务器与本地配出共享密钥!</b></button><br>
<h3>共享密钥:</h3>
<p>16进制表示</p>
<div id="output16" class="outputbox" style='background-color:cornflowerblue'>暂无</div>
<p> <a href='./demo_cbc.html'>选择一 -> 继续文本加密解密</a> </p>
<!-- 正文内容结束-->
</div>
<div id='footbar'>
<button class='btn' onclick='maximize_footer()'>⊼</button>
<button class='btn' onclick='increase_footer()'>⋀</button>
<b> 程序 执行 过程 </b>
<button class='btn' onclick='decrease_footer()'>⋁</button>
<button class='btn' style='font-weight:600' onclick='hide_footer()'>⊻</button>
</div>
<div id='logger'>
</div>
<script>
function getMyEck(){
MyEck = genkey();
let myLock = b2Base64(MyEck.public);
sessionStorage.setItem('myLock', myLock);
log('已经生成本机专用密钥。');
document.getElementById("client-sk").innerText = b2Hex(MyEck.private);
document.getElementById("client-pk").innerText = myLock;
newStatus('本地密钥可用');
}
function getShared(){
let url = document.getElementById("URL").value; //测试版
mingle(url).then( ()=>{
log('after mingle');
document.getElementById("output16").innerText = sessionStorage.sharedSecret;
newStatus('端到端加密中');
setExpire(600);
}
);
// javascript特有的async传染,必须把async函数之后的所有语句都扔进then里
}
</script>
</body>
</html>