encryption POC

This commit is contained in:
azivner 2017-08-21 20:34:17 -04:00
parent d775947daa
commit 0c602299b2
3 changed files with 51 additions and 5 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
export FLASK_DEBUG=0
export FLASK_DEBUG=1
export FLASK_APP=src/app.py
flask run

View File

@ -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">

View File

@ -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);
}