Exemplo n.º 1
0
        public static EncryptedDiaryRecord EncryptRecord(DiaryRecord record, RSACryptoServiceProvider rsa)
        {
            var rij = Rijndael.Create();

            rij.KeySize = 256;
            rij.GenerateKey();
            rij.GenerateIV();

            var encryptedRecord = new EncryptedDiaryRecord();

            var header = new MemoryStream();

            header.Write(rij.Key, 0, rij.Key.Length);
            header.Write(rij.IV, 0, rij.IV.Length);

            encryptedRecord.Header = rsa.Encrypt(header.ToArray(), false);

            var encryptedBodyStream = new MemoryStream();

            using (var body = new CryptoStream(encryptedBodyStream, rij.CreateEncryptor(), CryptoStreamMode.Write))
            {
                Serializer.Serialize(body, record);
            }

            encryptedRecord.Body = encryptedBodyStream.ToArray();

            return(encryptedRecord);
        }
Exemplo n.º 2
0
        public void AddRecord(DiaryRecord record)
        {
            if (!IsOpen)
            {
                throw new InvalidOperationException("Please open the diary before writing to it");
            }

            _fileStream.Seek(0, SeekOrigin.End);

            WriteRecords(new[] { record });
        }
Exemplo n.º 3
0
        private void AddToTree(DiaryRecord record)
        {
            var folder = record.Created.Date.ToString("yyyy-MM");
            var node   = entriesTreeView.Nodes[folder];

            if (node == null)
            {
                node = entriesTreeView.Nodes.Add(folder, folder);
            }

            var entryNode = node.Nodes.Add(record.Created.ToString());

            entryNode.Tag = record;
        }
Exemplo n.º 4
0
        private async void writeButton_Click(object sender, EventArgs e)
        {
            if (mainTextBox.ReadOnly)
            {
                tagsTextBox2.Text     = "";
                mainTextBox.Text      = "";
                dateLabel.Text        = string.Format(Strings.TodayIs, DateTime.Today.ToLongDateString());
                writeButton.Text      = Strings.WriteDown;
                mainTextBox.ReadOnly  = false;
                tagsTextBox2.ReadOnly = false;
                return;
            }

            if (string.IsNullOrEmpty(mainTextBox.Text))
            {
                MessageBox.Show(Strings.WriteSomething);
                return;
            }

            var diaryRecord = new DiaryRecord();

            diaryRecord.Created = DateTime.Now;
            diaryRecord.Content = mainTextBox.Text;
            diaryRecord.Tags    = tagsTextBox2.Text;

            try
            {
                _diary.AddRecord(diaryRecord);
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            if (!_diary.IsLocked)
            {
                await LoadEntries();
            }

            tagsTextBox2.Text = "";
            mainTextBox.Text  = "";
        }
Exemplo n.º 5
0
 protected bool Equals(DiaryRecord other)
 {
     return(string.Equals(Title, other.Title) && Created.Equals(other.Created) && string.Equals(Content, other.Content) && string.Equals(Tags, other.Tags));
 }