-
Notifications
You must be signed in to change notification settings - Fork 98
/
sm2.html
executable file
·53 lines (43 loc) · 1.66 KB
/
sm2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SM2</title>
<script src="./lib/crypto-js.js"></script>
<script src="./sm2.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<h1>SM2</h1>
<div class="toolbar">
<input type="text" value="hello world" placeholder="请输入当前要加密的文本" id="encode-text" />
<button onclick="generateCipher()">生成 20 条密文</button>
<button onclick="clearCipher()">清空密文</button>
</div>
<ul id="cipher-items" style="font-size: 14px;">
</ul>
<script>
var pubkeyHex =
"0452712EBA7FE2C9615F6DE59C6EF662R085BD52B25952597CC95014BB8F201987F8D818EFFE710DBEC08FE2E4C7E3E0113EEBAB4B0E8B044E1A3CC8B149D76BE7";
var keyCollection = [];
var $cipherItems = $('#cipher-items');
var $msg = $('#encode-text');
function generateCipher() {
var item = '';
var msg = $msg.val();
for (var i = 0, len = 20; i < len; i++) {
var encryptData = sm2Encrypt(msg, pubkeyHex, 0);
keyCollection.push(encryptData);
item += `<li class="cipher-items-item">{SM2}${encryptData}</li>`
}
$cipherItems.html($cipherItems.html() + item);
}
function clearCipher() {
keyCollection = [];
$cipherItems.html();
}
</script>
</body>
</html>