js_lis 1.0.15 → 1.0.17
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 +30 -65
- package/package.json +1 -1
package/VirtualKeyboard.js
CHANGED
|
@@ -12,17 +12,16 @@ export class VirtualKeyboard {
|
|
|
12
12
|
this.offsetY = 0;
|
|
13
13
|
this.shiftActive = false;
|
|
14
14
|
this.capsLockActive = false;
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
this.
|
|
18
|
-
this.iv =
|
|
19
|
-
|
|
15
|
+
|
|
16
|
+
// กำหนดคีย์และ IV สำหรับการเข้ารหัส
|
|
17
|
+
this.secretKey = '1234567890abcdef1234567890abcdef'; // คีย์ความยาว 32 bytes
|
|
18
|
+
this.iv = CryptoJS.lib.WordArray.random(16); // สร้าง IV ความยาว 16 bytes
|
|
19
|
+
|
|
20
20
|
this.initialize();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async initialize() {
|
|
24
24
|
try {
|
|
25
|
-
await this.generateKey();
|
|
26
25
|
this.render();
|
|
27
26
|
this.initializeInputListeners();
|
|
28
27
|
console.log("VirtualKeyboard initialized successfully.");
|
|
@@ -30,65 +29,30 @@ export class VirtualKeyboard {
|
|
|
30
29
|
console.error("Error initializing VirtualKeyboard:", error);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
console.error("Web Crypto API is not supported in this environment.");
|
|
49
|
-
throw new Error("Web Crypto API is not supported.");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async encodeText(text) {
|
|
55
|
-
const encodedData = new TextEncoder().encode(text);
|
|
56
|
-
const encryptedData = await window.crypto.subtle.encrypt(
|
|
57
|
-
{ name: "AES-GCM", iv: this.iv },
|
|
58
|
-
this.cryptoKey,
|
|
59
|
-
encodedData
|
|
60
|
-
);
|
|
61
|
-
return this.arrayBufferToBase64(encryptedData); // แปลงเป็น Base64
|
|
33
|
+
encodeText(text) {
|
|
34
|
+
const encrypted = CryptoJS.AES.encrypt(text, CryptoJS.enc.Hex.parse(this.secretKey), {
|
|
35
|
+
iv: this.iv,
|
|
36
|
+
mode: CryptoJS.mode.CBC,
|
|
37
|
+
padding: CryptoJS.pad.Pkcs7
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
encrypted: encrypted.ciphertext.toString(CryptoJS.enc.Base64),
|
|
41
|
+
iv: this.iv.toString(CryptoJS.enc.Base64)
|
|
42
|
+
};
|
|
62
43
|
}
|
|
63
44
|
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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.CBC,
|
|
52
|
+
padding: CryptoJS.pad.Pkcs7
|
|
53
|
+
}
|
|
70
54
|
);
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
arrayBufferToBase64(buffer) {
|
|
75
|
-
let binary = '';
|
|
76
|
-
const bytes = new Uint8Array(buffer);
|
|
77
|
-
const len = bytes.byteLength;
|
|
78
|
-
for (let i = 0; i < len; i++) {
|
|
79
|
-
binary += String.fromCharCode(bytes[i]);
|
|
80
|
-
}
|
|
81
|
-
return window.btoa(binary);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
base64ToArrayBuffer(base64) {
|
|
85
|
-
const binaryString = window.atob(base64);
|
|
86
|
-
const len = binaryString.length;
|
|
87
|
-
const bytes = new Uint8Array(len);
|
|
88
|
-
for (let i = 0; i < len; i++) {
|
|
89
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
90
|
-
}
|
|
91
|
-
return bytes.buffer;
|
|
55
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
92
56
|
}
|
|
93
57
|
|
|
94
58
|
getLayoutName(layout) {
|
|
@@ -99,6 +63,7 @@ export class VirtualKeyboard {
|
|
|
99
63
|
case 'thSc': return 'Thai scrambled';
|
|
100
64
|
case 'numpad': return 'Numpad Keyboard';
|
|
101
65
|
case 'scNum': return 'Scrambled Keyboard';
|
|
66
|
+
default: return 'Unknown Layout';
|
|
102
67
|
}
|
|
103
68
|
}
|
|
104
69
|
|
|
@@ -117,10 +82,10 @@ export class VirtualKeyboard {
|
|
|
117
82
|
}
|
|
118
83
|
}, true);
|
|
119
84
|
|
|
120
|
-
document.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
85
|
+
const toggle = document.getElementById("toggle");
|
|
86
|
+
if (toggle) {
|
|
87
|
+
toggle.addEventListener('click', this.toggle.bind(this));
|
|
88
|
+
}
|
|
124
89
|
}
|
|
125
90
|
|
|
126
91
|
setCurrentInput(inputElement) {
|