public void Lock() { byte[] message = null; byte[] password = null; SafeExecute(() => { if (IsLocked) { OnError("This note is already Locked!"); return; } if (IsEmpty) { OnError("There is no data to unlock!"); return; } if (!IsUnlocked) { OnError("Unknown instruction for this lock state. Please alert a developer."); } if (!IsPasswordSet) { OnError("Password has not been set!"); } _encryptedData ??= new CryptoNote(UserSettings.Default.Iterations); message = _vulnerableData.Message.GetPlainText(); password = _vulnerableData.Password.GetPlainText(); _encryptedData.Encrypt(message, password); ClearVulnerableData(); }, message, password); }
public CryptoNote GenerateEncryptedOutput() { byte[] message = null; byte[] password = null; CryptoNote note = null; SafeExecute(() => { if (IsLocked) { note = _encryptedData; return; } if (IsEmpty) { OnError("This note is empty!"); return; } if (!IsUnlocked) { OnError("Unknown instruction for this lock state. Please alert a developer."); } note ??= new CryptoNote(UserSettings.Default.Iterations) { OnError = OnError }; message = _vulnerableData.Message.GetPlainText(); password = _vulnerableData.Password.GetPlainText(); note.Iterations = UserSettings.Default.Iterations; note.Encrypt(message, password); }, message, password); return(note); }
public void TestEncryptDecrypt() { var note = new CryptoNote(defaultIterations); note.Encrypt(Message, Password); Debug.WriteLine(Message.ToText()); Debug.WriteLine(note.Cipher.ToText()); Assert.IsTrue(note.TryDecrypt(Password, out var decrypted)); TestFunctions.AssertValueEquality(Message, decrypted); }
public void Test() { var note = new CryptoNote(defaultIterations); note.Encrypt(Message, Password); var path = MakeTestFilePath(); Writer.SaveToFile(note, path); Assert.IsTrue(new Reader().TryRead(path, out var loadedNote)); AssertValueEquality(note.Salt, loadedNote.Salt); Assert.AreEqual(note.Iterations, loadedNote.Iterations); AssertValueEquality(note.InitializationVector, loadedNote.InitializationVector); AssertValueEquality(note.ValidityCheck, loadedNote.ValidityCheck); AssertValueEquality(note.Cipher, loadedNote.Cipher); Assert.IsTrue(loadedNote.TryDecrypt(Password, out var loadedMessage)); AssertValueEquality(Message, loadedMessage); }