-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (31 loc) · 1.1 KB
/
app.js
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
const buttonEncrypt = document.getElementById("button-encrypt");
const buttonDecrypt = document.getElementById("button-decrypt");
const buttonCopy = document.getElementById("button-copy");
const messageResult = document.getElementById("result");
const alert = document.getElementById("alert");
// Encriptar texto
buttonEncrypt.addEventListener("click", (e) => {
e.preventDefault();
const message = document.getElementById("message");
var encrypted = CryptoJS.AES.encrypt(message.value, "123").toString();
messageResult.value = encrypted;
});
// Desencriptar texto
buttonDecrypt.addEventListener("click", (e) => {
e.preventDefault();
const message = document.getElementById("message");
var decrypted = CryptoJS.AES.decrypt(message.value, "123").toString(
CryptoJS.enc.Utf8
);
messageResult.value = decrypted;
});
// Copiar texto
buttonCopy.addEventListener("click", (e) => {
messageResult.select();
messageResult.setSelectionRange(0, 99999);
navigator.clipboard.writeText(messageResult.value);
alert.classList.add('active');
setTimeout(() => {
alert.classList.remove('active');
}, 3000);
})