js_lis 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VirtualKeyboard.js +38 -67
- package/package.json +1 -1
package/VirtualKeyboard.js
CHANGED
|
@@ -12,77 +12,47 @@ export class VirtualKeyboard {
|
|
|
12
12
|
this.offsetY = 0;
|
|
13
13
|
this.shiftActive = false;
|
|
14
14
|
this.capsLockActive = false;
|
|
15
|
-
this.secretKey = '1234567890abcdef'; // คีย์ที่ใช้ในการเข้ารหัส
|
|
16
|
-
// ใช้ Web Crypto API สำหรับการจัดการคีย์
|
|
17
|
-
this.cryptoKey = null;
|
|
18
|
-
this.iv = window.crypto.getRandomValues(new Uint8Array(12)); // สร้าง IV สำหรับการเข้ารหัส/ถอดรหัส
|
|
19
|
-
|
|
20
|
-
this.initialize();
|
|
21
|
-
}
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.render();
|
|
27
|
-
this.initializeInputListeners();
|
|
28
|
-
console.log("VirtualKeyboard initialized successfully.");
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error("Error initializing VirtualKeyboard:", error);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async generateKey() {
|
|
35
|
-
try {
|
|
36
|
-
this.cryptoKey = await window.crypto.subtle.generateKey(
|
|
37
|
-
{ name: "AES-GCM", length: 256 },
|
|
38
|
-
true,
|
|
39
|
-
["encrypt", "decrypt"]
|
|
40
|
-
);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error("Error generating key:", error);
|
|
43
|
-
throw error;
|
|
44
|
-
// rethrow the error to be caught in initialize
|
|
45
|
-
}
|
|
46
|
-
}
|
|
16
|
+
// กำหนดคีย์และ IV สำหรับการเข้ารหัส
|
|
17
|
+
this.secretKey = '1234567890abcdef1234567890abcdef'; // คีย์ความยาว 32 bytes
|
|
18
|
+
this.iv = CryptoJS.lib.WordArray.random(16); // สร้าง IV ความยาว 16 bytes
|
|
47
19
|
|
|
48
|
-
|
|
49
|
-
const encodedData = new TextEncoder().encode(text);
|
|
50
|
-
const encryptedData = await window.crypto.subtle.encrypt(
|
|
51
|
-
{ name: "AES-GCM", iv: this.iv },
|
|
52
|
-
this.cryptoKey,
|
|
53
|
-
encodedData
|
|
54
|
-
);
|
|
55
|
-
return this.arrayBufferToBase64(encryptedData); // แปลงเป็น Base64
|
|
20
|
+
this.initialize();
|
|
56
21
|
}
|
|
57
22
|
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
23
|
+
async initialize() {
|
|
24
|
+
try {
|
|
25
|
+
this.render();
|
|
26
|
+
this.initializeInputListeners();
|
|
27
|
+
console.log("VirtualKeyboard initialized successfully.");
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error("Error initializing VirtualKeyboard:", error);
|
|
30
|
+
}
|
|
66
31
|
}
|
|
67
32
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
33
|
+
encodeText(text) {
|
|
34
|
+
const encrypted = CryptoJS.AES.encrypt(text, CryptoJS.enc.Hex.parse(this.secretKey), {
|
|
35
|
+
iv: this.iv,
|
|
36
|
+
mode: CryptoJS.mode.GCM,
|
|
37
|
+
format: CryptoJS.format.Hex
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
encrypted: encrypted.ciphertext.toString(CryptoJS.enc.Base64),
|
|
41
|
+
iv: this.iv.toString(CryptoJS.enc.Base64)
|
|
42
|
+
};
|
|
76
43
|
}
|
|
77
44
|
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
45
|
+
decodeText(encryptedData) {
|
|
46
|
+
const decrypted = CryptoJS.AES.decrypt(
|
|
47
|
+
{ ciphertext: CryptoJS.enc.Base64.parse(encryptedData.encrypted) },
|
|
48
|
+
CryptoJS.enc.Hex.parse(this.secretKey),
|
|
49
|
+
{
|
|
50
|
+
iv: CryptoJS.enc.Base64.parse(encryptedData.iv),
|
|
51
|
+
mode: CryptoJS.mode.GCM,
|
|
52
|
+
format: CryptoJS.format.Hex
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
86
56
|
}
|
|
87
57
|
|
|
88
58
|
getLayoutName(layout) {
|
|
@@ -93,6 +63,7 @@ export class VirtualKeyboard {
|
|
|
93
63
|
case 'thSc': return 'Thai scrambled';
|
|
94
64
|
case 'numpad': return 'Numpad Keyboard';
|
|
95
65
|
case 'scNum': return 'Scrambled Keyboard';
|
|
66
|
+
default: return 'Unknown Layout';
|
|
96
67
|
}
|
|
97
68
|
}
|
|
98
69
|
|
|
@@ -111,10 +82,10 @@ export class VirtualKeyboard {
|
|
|
111
82
|
}
|
|
112
83
|
}, true);
|
|
113
84
|
|
|
114
|
-
document.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
85
|
+
const toggle = document.getElementById("toggle");
|
|
86
|
+
if (toggle) {
|
|
87
|
+
toggle.addEventListener('click', this.toggle.bind(this));
|
|
88
|
+
}
|
|
118
89
|
}
|
|
119
90
|
|
|
120
91
|
setCurrentInput(inputElement) {
|