-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.html
38 lines (29 loc) · 821 Bytes
/
test.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
<html>
<script src="js/sm3.js"></script>
<script src="js/sm4.js"></script>
<body>
<h1>GmSSL JavaScript</h1>
<script>
var m = [0x61, 0x62, 0x63];
var dgst = sm3(m);
console.log("sm3(\"abc\") = " + dgst);
var user_key = [
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
];
var plaintext = [
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
];
var key = sm4_key_new();
var ciphertext = new Array(SM4_BLOCK_SIZE);
sm4_set_encrypt_key(key, user_key);
sm4_encrypt(plaintext, 0, ciphertext, 0, key);
console.log("sm4 ciphertext = " + ciphertext);
sm4_set_decrypt_key(key, user_key);
sm4_decrypt(ciphertext, 0, plaintext, 0, key);
console.log("sm4 plaintext = " + plaintext);
sm4_key_free(key);
</script>
</body>
</html>