예제 #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);
        }
예제 #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 });
        }
예제 #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;
        }
예제 #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  = "";
        }
예제 #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));
 }