-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (29 loc) · 1.2 KB
/
Copy pathscript.js
File metadata and controls
35 lines (29 loc) · 1.2 KB
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
// import CryptoJS from "https://cdn.jsdelivr.net/npm/crypto-js@4.2.0/+esm";
function encryptData(plainText, secretKey) {
const key = CryptoJS.enc.Utf8.parse(secretKey);
const encrypted = CryptoJS.AES.encrypt(plainText, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
function decryptData(cipherText, secretKey) {
const key = CryptoJS.enc.Utf8.parse(secretKey);
const decrypted = CryptoJS.AES.decrypt(cipherText, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return decrypted.toString(CryptoJS.enc.Utf8);
}
window.encrypt = function() {
const plainText = document.getElementById("inputMessage").value;
const key = document.getElementById("inputKey").value;
const encryptedMessage = encryptData(plainText, key);
document.getElementById("outputDisplay").innerText = encryptedMessage;
}
window.decrypt = function() {
const cipherText = document.getElementById("inputMessage").value;
const key = document.getElementById("inputKey").value;
const decryptedMessage = decryptData(cipherText, key);
document.getElementById("outputDisplay").innerText = decryptedMessage;
}