-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
66 lines (63 loc) · 2.47 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html xmlns="http://www.w3.org/1999/html" lang="en">
<head>
<title>Cipher Text</title>
<link rel="stylesheet" href="index.css"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/forge.min.js"></script>
<script src="env.js"></script>
<script>
let iv = env.IV;
let salt = env.SALT;
function encrypt() {
console.log("Hello")
console.log('iv', iv);
console.log('salt', salt);
const password = document.getElementById("secretText").value;
if (password != null && password.length > 0) {
const value = document.getElementById("inputValue").value;
const key = forge.pkcs5.pbkdf2(password, salt, 10000, 32);
const cipher = forge.cipher.createCipher("AES-CBC", key);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer(value));
cipher.finish();
document.getElementById("result").value = forge.util.encode64(cipher.output.data);
}
}
function decrypt() {
const password = document.getElementById("secretText").value;
if (password != null && password.length > 0) {
const value = document.getElementById("inputValue").value;
const key = forge.pkcs5.pbkdf2(password, salt, 10000, 32);
const decipher = forge.cipher.createDecipher("AES-CBC", key);
decipher.start({iv: iv});
decipher.update(forge.util.createBuffer(forge.util.decode64(value)));
decipher.finish();
document.getElementById("result").value = decipher.output.data;
}
}
function copy() {
const result = document.getElementById("result").value;
navigator.clipboard.writeText(result);
}
</script>
</head>
<body>
<h1> Let's share secrets </h1>
<label>
<textarea name="input" id="inputValue" placeholder="input" rows="10" cols="50"></textarea>
</label>
<br/>
<label>
<input type="password" name="password" placeholder="secret" id="secretText"/>
</label>
<br/>
<div class="buttons">
<button name="encrypt" onclick="encrypt()">Encrypt</button>
<button name="decrypt" onclick="decrypt()">Decrypt</button>
</div>
<br/>
<label>
<textarea name="result" id="result" placeholder="result" rows="10" cols="50" disabled></textarea>
</label>
<button name="copy" onclick="copy()">Copy</button>
</body>
</html>