Beispiel #1
0
        public void SetNoteTitleTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

            string title = "Wishlist for holidays part IV";
            string text  = "peace, happiness, freedom and something...";

            Note note = new Note(title, text);

            NoteSecret noteSecret = new NoteSecret(note, "does not matter", ska, derivedKey);

            string noteTitle1 = "future text that is happy and joyful for all holiday purposes...";

            // Act
            bool   shouldBeTrue  = noteSecret.SetNoteTitle(noteTitle1, derivedKey);
            string noteTitle2    = noteSecret.GetNoteTitle(derivedKey);
            bool   shouldBeFalse = noteSecret.SetNoteTitle(noteTitle1, new byte[] { 1, 2, 3 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.IsFalse(string.IsNullOrEmpty(noteTitle2));
            Assert.AreEqual(noteTitle1, noteTitle2);
        }
Beispiel #2
0
        public void DeepCopyTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 1, 82, 93, 102, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xf5, 0xf6, 0xbb, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            string title = "Wishlist for holidays";
            string text  = "peace, happiness, freedom and something";

            Note note = new Note(title, text);

            NoteSecret noteSecret = new NoteSecret(note, "does not matter", skaAES_CTR, derivedKey);

            // Act
            NoteSecret noteSecretCopy = new NoteSecret(noteSecret);
            string     noteTitle      = noteSecretCopy.GetNoteTitle(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(noteTitle));
            Assert.AreEqual(title, noteTitle);
            Assert.AreNotSame(noteSecret.audalfData, noteSecretCopy.audalfData, "AUDALF byte arrays should be in different memory locations");
            CollectionAssert.AreEqual(noteSecret.keyIdentifier, noteSecretCopy.keyIdentifier);
            Assert.AreNotSame(noteSecret.keyIdentifier, noteSecretCopy.keyIdentifier, "Key identifier byte arrays should be in different memory locations");
            Assert.AreEqual(noteSecret.checksum, noteSecretCopy.checksum);
        }
Beispiel #3
0
        public void GetNoteTitleTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            string title = "Wishlist for holidays";
            string text  = "peace, happiness, freedom";

            Note note = new Note(title, text);

            NoteSecret noteSecret = new NoteSecret(note, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string noteTitle = noteSecret.GetNoteTitle(derivedKey);

            // Assert
            Assert.AreEqual(title, noteTitle);
        }
 public static NoteSimplified TurnIntoEditable(NoteSecret noteSecret, byte[] derivedPassword, int zeroBasedIndexNumber)
 {
     return(new NoteSimplified()
     {
         zeroBasedIndexNumber = zeroBasedIndexNumber,
         IsSecure = true,
         Title = noteSecret.GetNoteTitle(derivedPassword),
         Text = noteSecret.GetNoteText(derivedPassword),
         CreationTime = noteSecret.GetCreationTime(derivedPassword).ToString("s", System.Globalization.CultureInfo.InvariantCulture),
         ModificationTime = noteSecret.GetModificationTime(derivedPassword).ToString("s", System.Globalization.CultureInfo.InvariantCulture),
     });
 }