Skip to content

Build your personal knowledge base with Trilium Notes

encryption POC

azivner0c602299b28a
diff --git a/run-debug.sh b/run-debug.sh
index 1cf658d8e9..7a6afb26bf 100644
--- a/run-debug.sh
+++ b/run-debug.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-export FLASK_DEBUG=0
+export FLASK_DEBUG=1
export FLASK_APP=src/app.py
flask run
\ No newline at end of file
diff --git a/src/templates/app.html b/src/templates/app.html
index 0f5b9932a6..46d026f193 100644
--- a/src/templates/app.html
+++ b/src/templates/app.html
@@ -26,8 +26,10 @@
</form>
</div>
- <div style="float: left; margin: 5px;">
- <input type="text" autocomplete="off" value="Welcome to Notecase web app!" id="noteTitle" style="font-size: x-large; border: 0; width: 650px;">
+ <div style="float: left; margin: 0 5px 5px 5px;">
+ <input type="text" autocomplete="off" value="Welcome to Notecase web app!" id="noteTitle" style="font-size: x-large; border: 0; width: 600px;">
+
+ <button class="btn btn-sm" onclick="encryptNote();">Encrypt</button>
</div>
<div style="clear: both; height: 0"></div>
@@ -65,6 +67,13 @@
<script src="stat/lib/jquery.hotkeys.js"></script>
<script src="stat/lib/jquery.fancytree.hotkeys.js"></script>
+ <!-- https://github.com/ricmoo/aes-js -->
+ <script src="stat/lib/aes.js"></script>
+ <!-- https://github.com/dcodeIO/bcrypt.js -->
+ <script src="stat/lib/bcrypt.min.js"></script>
+ <!-- https://github.com/emn178/js-sha256 -->
+ <script src="stat/lib/sha256.min.js"></script>
+
<link href="stat/style.css" rel="stylesheet">
<script type="text/javascript">
diff --git a/static/js/note.js b/static/js/note.js
index 7bd80e855d..3685af85a2 100644
--- a/static/js/note.js
+++ b/static/js/note.js
@@ -34,12 +34,12 @@ function saveNoteIfChanged(callback) {
let contents = $('#noteDetail').summernote('code');
+ html2notecase(contents, note);
+
let title = $('#noteTitle').val();
$("#tree").fancytree('getNodeByKey', note.detail.note_id).setTitle(title);
- html2notecase(contents, note);
-
note.detail.note_title = title;
const note_id = note.detail.is_clone ? note.detail.note_clone_id : note.detail.note_id;
@@ -161,4 +161,41 @@ function loadNote(noteId) {
noteChangeDisabled = false;
});
+}
+
+function encryptNote() {
+ let password = prompt("Enter password for encryption");
+
+ console.log(password);
+
+ // 12 takes about 400 ms on my computer to compute
+ let salt = dcodeIO.bcrypt.genSaltSync(12);
+
+ let hashedPassword = dcodeIO.bcrypt.hashSync(password, salt);
+
+ let hashedPasswordSha = sha256(hashedPassword).substr(0, 32);
+
+ console.log(hashedPassword);
+
+ let note = globalNote;
+
+ let contents = $('#noteDetail').summernote('code');
+
+ html2notecase(contents, note);
+
+ let noteJson = JSON.stringify(note);
+
+ console.log('json: ' + noteJson);
+
+ let hashedPasswordBytes = aesjs.utils.hex.toBytes(hashedPasswordSha);
+
+ let noteBytes = aesjs.utils.utf8.toBytes(noteJson);
+
+ let aesCtr = new aesjs.ModeOfOperation.ctr(hashedPasswordBytes, new aesjs.Counter(5));
+ let encryptedBytes = aesCtr.encrypt(noteBytes);
+
+ // To print or store the binary data, you may convert it to hex
+ let encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
+
+ console.log("encrypted: " + encryptedBytes);
}
\ No newline at end of file