Ejemplo n.º 1
0
        public void CanBeDecryptedWithDerivedPassword()
        {
            byte[] derivedKey1 = new byte[16] {
                11, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 16
            };
            byte[] derivedKey2 = new byte[16] {
                11, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 15
            };
            byte[] initialCounter = new byte[] { 0xa7, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0xd3, 0xb5, 0x58, 0x51, 0x95, 0x2b, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

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

            string keyIdentifier = "primary";

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

            Note note = new Note(title, text);

            // Act
            NoteSecret noteSecret = new NoteSecret(note, keyIdentifier, skaAES_CTR, derivedKey1);

            // Assert
            Assert.IsTrue(noteSecret.CanBeDecryptedWithDerivedPassword(derivedKey1));
            Assert.IsFalse(noteSecret.CanBeDecryptedWithDerivedPassword(null));
            Assert.IsFalse(noteSecret.CanBeDecryptedWithDerivedPassword(new byte[] {}));
            Assert.IsFalse(noteSecret.CanBeDecryptedWithDerivedPassword(derivedKey2));
        }