public void GetKeyIdentifierTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 47, 25, 138, 78, 83, 111, 110, 221, 18, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xa0, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0x13, 0xb5, 0x58, 0x59, 0x13, 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 filename = "nice.pdf";

            byte[] fileContent = new byte[] { 1, 2, 3, 1, 2, byte.MaxValue, 0, 0, 0, 0, 0, 0 };

            FileEntry fe = new FileEntry(filename, fileContent);

            // Act
            FileEntrySecret fes = new FileEntrySecret(fe, keyIdentifier, skaAES_CTR, derivedKey);

            // Assert
            Assert.AreEqual(keyIdentifier, fes.GetKeyIdentifier());
        }
Exemple #2
0
    private void EditFileInCollection(int zeroBasedIndexNumber, bool isNowSecure, bool wasSecurityModified, string keyIdentifier)
    {
        if (wasSecurityModified)
        {
            // If file jumps from secure <-> unsecure
            if (isNowSecure)
            {
                this.csc.AddFileEntrySecret(this.derivedPasswords[keyIdentifier], this.csc.files[zeroBasedIndexNumber], keyIdentifier);
                this.csc.files.RemoveAt(zeroBasedIndexNumber);
            }
            else
            {
                FileEntrySecret fes             = this.csc.fileSecrets[zeroBasedIndexNumber];
                byte[]          derivedPassword = derivedPasswords[fes.GetKeyIdentifier()];
                FileEntry       tempFileEntry   = new FileEntry(fes.GetFilename(derivedPassword), fes.GetFileContent(derivedPassword));
                this.csc.fileSecrets.RemoveAt(zeroBasedIndexNumber);
                this.csc.files.Add(tempFileEntry);
            }
        }
        else
        {
            if (isNowSecure)
            {
                // TODO: support key change
            }
        }

        // Editing a file modifies the structure
        this.isModified = true;
        this.UpdateMainTitle(this.filePath != null ? this.filePath : untitledTempName);

        this.GenerateFileSimplifiedsFromCommonSecrets();
    }