public static void Decrypt(this DBNote note, DBUser user, string master_key) { var per_note_key = note.EncryptedKey.DecryptWithKey(master_key, user.MasterKeySalt); byte[] b_key = per_note_key.ToByteArray(); byte[] b_note_text = note.Text.ToByteArray(); note.Text = user.DecryptUnicodeString(b_key, b_note_text); }
public void BasicEncryptAndDecrypt() { var u = new DBUser(); u.Username = "******"; var password = "******"; u.CreateCryptoFields(password); var test_string = "The quick brown fox jumps over the lazy dog."; var master_key = u.GetPlaintextMasterKey(password); byte[] encrypted_bytes = u.EncryptString(master_key, test_string); string decrypted_string = u.DecryptUnicodeString(master_key, encrypted_bytes); Assert.AreEqual(test_string, decrypted_string); }
public void EncryptDecryptWithHexRepresentation() { var u = new DBUser(); u.Username = "******"; var password = "******"; u.CreateCryptoFields(password); var master_key = u.GetPlaintextMasterKey(password); var key = master_key.ToHexString(); var test_string = "The quick brown fox jumps over the lazy dog."; byte[] encrypted_bytes = u.EncryptString(master_key, test_string); string encrypted_string = encrypted_bytes.ToHexString(); string decrypted_string = u.DecryptUnicodeString(master_key, encrypted_string.ToByteArray()); Assert.AreEqual(test_string, decrypted_string); }