mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	encryption POC
This commit is contained in:
		
							parent
							
								
									d775947daa
								
							
						
					
					
						commit
						0c602299b2
					
				| @ -1,6 +1,6 @@ | |||||||
| #!/bin/sh | #!/bin/sh | ||||||
| 
 | 
 | ||||||
| export FLASK_DEBUG=0 | export FLASK_DEBUG=1 | ||||||
| export FLASK_APP=src/app.py | export FLASK_APP=src/app.py | ||||||
| 
 | 
 | ||||||
| flask run | flask run | ||||||
| @ -26,8 +26,10 @@ | |||||||
|           </form> |           </form> | ||||||
|         </div> |         </div> | ||||||
| 
 | 
 | ||||||
|         <div style="float: left; margin: 5px;"> |         <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: 650px;"> |           <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> | ||||||
| 
 | 
 | ||||||
|         <div style="clear: both; height: 0"></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.hotkeys.js"></script> | ||||||
|     <script src="stat/lib/jquery.fancytree.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"> |     <link href="stat/style.css" rel="stylesheet"> | ||||||
| 
 | 
 | ||||||
|     <script type="text/javascript"> |     <script type="text/javascript"> | ||||||
|  | |||||||
| @ -34,12 +34,12 @@ function saveNoteIfChanged(callback) { | |||||||
| 
 | 
 | ||||||
|     let contents = $('#noteDetail').summernote('code'); |     let contents = $('#noteDetail').summernote('code'); | ||||||
| 
 | 
 | ||||||
|  |     html2notecase(contents, note); | ||||||
|  | 
 | ||||||
|     let title = $('#noteTitle').val(); |     let title = $('#noteTitle').val(); | ||||||
| 
 | 
 | ||||||
|     $("#tree").fancytree('getNodeByKey', note.detail.note_id).setTitle(title); |     $("#tree").fancytree('getNodeByKey', note.detail.note_id).setTitle(title); | ||||||
| 
 | 
 | ||||||
|     html2notecase(contents, note); |  | ||||||
| 
 |  | ||||||
|     note.detail.note_title = title; |     note.detail.note_title = title; | ||||||
| 
 | 
 | ||||||
|     const note_id = note.detail.is_clone ? note.detail.note_clone_id : note.detail.note_id; |     const note_id = note.detail.is_clone ? note.detail.note_clone_id : note.detail.note_id; | ||||||
| @ -162,3 +162,40 @@ function loadNote(noteId) { | |||||||
|         noteChangeDisabled = false; |         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); | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner