Example #1
0
        private void DecryptNoteBody(DBNote note)
        {
            if (!note.IsEncypted)
                return;

            note.Decrypt (User, encryptionMasterKey);
            note.IsEncypted = false;
        }
Example #2
0
        private string GetEncryptedNoteKey(DBNote note)
        {
            // re-use the same key when saving a note
            string encrypted_per_note_key;

            var saved_note = db.FirstOrDefault<DBNote> (n => n.CompoundPrimaryKey == note.CompoundPrimaryKey);
            if (saved_note != null) {
                encrypted_per_note_key = saved_note.EncryptedKey;
            } else {
                // new note, generate a new key
                var rng = new RNGCryptoServiceProvider ();
                encrypted_per_note_key = rng.Create256BitLowerCaseHexKey ().EncryptWithKey (encryptionMasterKey, User.MasterKeySalt);
            }
            return encrypted_per_note_key;
        }
Example #3
0
 private void EncryptNoteBody(DBNote note)
 {
     // decrypt the per note key
     var plaintext_key = note.EncryptedKey.DecryptWithKey (encryptionMasterKey, User.MasterKeySalt);
     note.IsEncypted = true;
     note.Text = User.EncryptString (plaintext_key.ToByteArray (), note.Text).ToHexString ();
 }
        protected void SaveDBNote(DBNote db_note)
        {
            // archive any previously existing note into its own table
            // TODO: evaluate how we could re-use the same DBNote table, which will save us
            // a select + reinsert operation
            //			if (UseHistory) {
            //				var old_note = db.FirstOrDefault<DBNote> (n => n.CompoundPrimaryKey == db_note.CompoundPrimaryKey);
            //				if (old_note != null) {
            //					var archived_note = new DBArchivedNote ().PopulateWith (old_note);
            //					// set the last known revision
            //
            //					if (Manifest.NoteRevisions.Keys.Contains (db_note.Guid)) {
            //						archived_note.LastSyncRevision = Manifest.NoteRevisions[db_note.Guid];
            //					}
            //					db.Insert<DBArchivedNote> (archived_note);
            //				}
            //			}

            // unforunately, we can't know if that note already exist
            // so we delete any previous incarnations of that note and
            // re-insert
            db.Delete<DBNote> (n => n.CompoundPrimaryKey == db_note.CompoundPrimaryKey);
            db.Insert (db_note);
        }