-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
30 lines (27 loc) · 1.17 KB
/
main.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
window.onload = function(e){
var form = document.getElementById("new_note");
form.addEventListener("submit", function(e){
e.preventDefault();
var note = document.getElementById("note_message").value;
var password = document.getElementById("note_password").value;
var noteName = document.getElementById("note_name").value;
localStorage.setItem(noteName, encrypt(password, note));
var outputEl = document.getElementById("encrypted_output");
outputEl.innerText = "Stored note: " + noteName;
});
var decryptForm = document.getElementById("encrypted_note");
decryptForm.addEventListener("submit", function(e){
e.preventDefault();
var decryptedOutputEl = document.getElementById("decrypted_output");
var password = document.getElementById("encrypted_note_password").value;
var noteName = document.getElementById("encrypted_note_name").value;
decryptedOutputEl.innerText = decrypt(password, noteName);
});
function encrypt(password, data) {
return sjcl.encrypt(password, data);
}
function decrypt(password, noteName) {
var noteJsonString = localStorage.getItem(noteName);
return sjcl.decrypt(password, noteJsonString);
}
}