예제 #1
0
        public void Run(TWorkflowOptions workflowDetails)
        {
            Contract.Requires <ArgumentNullException>(workflowDetails != null, "options");
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(workflowDetails.CategoryName), "category name cannot be null or whitespace");
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(workflowDetails.DatFilePath), "DAT file path cannot be null or whitespace");
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(workflowDetails.EntryName), "entry name cannot be null or whitespace");
            //      PlainText decryption doesn't require a key
            //Contract.Requires<ArgumentException>(typeof(TKey) == typeof(PlainTextKey) || !string.IsNullOrWhiteSpace(options.KeyFilePath), "key file path cannot be null or whitespace");
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(workflowDetails.StringToEncrypt), "string to encrypt cannot be null or empty");
            //

            /*
             * Get key from file
             * Get Entries from file or create a new file if not already there
             *
             * Map keys to entries
             * Encrypt value using key (or leave in plain text)
             * Add encrypted value to POCO
             * Write POCO to file
             */

            TKey key;
            var  encryptedSegments = _encryptWorkflow.GetEncryptedSegments(GetKeyLoaderDetails(workflowDetails),
                                                                           workflowDetails.StringToEncrypt, out key);


            var datPoco = _datLoader.Load(GetDatLoaderOptions(workflowDetails));

            datPoco.AddEntry(workflowDetails.CategoryName, workflowDetails.EntryName, key, encryptedSegments, false);
            _datSaver.Save(datPoco, GetDatSaverOptions(workflowDetails));
        }
        public IList <EntriesDecrypterResult <TKey> > Run(TWorkflowOptions options)
        {
            Contract.Requires <ArgumentNullException>(options != null, "options");

            /*Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(options.DatFilePath), "DAT file path cannot be null or whitespace");*/

            Contract.Requires <ArgumentException>(Contract.ForAll(options.CategoryEntryPair, t => !string.IsNullOrWhiteSpace(t.Category)),
                                                  "none of the category names can be null or whitespace");
            Contract.Requires <ArgumentException>(Contract.ForAll(options.CategoryEntryPair, t => !string.IsNullOrWhiteSpace(t.Entry)),
                                                  "none of the entry names can be null or whitespace");

            /*Contract.Requires<ArgumentException>(typeof(TKey) == typeof(PlainTextKey) ||
             *  Contract.ForAll(options.KeyFilePaths, s => !string.IsNullOrWhiteSpace(s)),
             *  "key file path cannot be null or whitespace");*/
            Contract.Ensures(Contract.Result <IList <EntriesDecrypterResult <TKey> > >() != null);
            //

            var datPoco    = _datLoader.Load(GetDatLoaderOptions(options));
            var loadedKeys = LoadKeys(options);

            var ret = _entriesDecrypter.Decrypt(loadedKeys, datPoco, options.CategoryEntryPair, options.ThrowExceptionIfEntryNotFound, options.ThrowIfDecryptingKeyNotFound, options.ThrowIfKeyCannotDecrypt);

            _auditLogger.LogDecryption(options, datPoco, loadedKeys, ret);

            return(ret);
        }
        public void Run(TDatLoaderOptions datLoaderOptions, IList <CategoryEntryPair> entriesToRemove, TDatSaverOptions datSaverOptions)
        {
            var dat = _datLoader.Load(datLoaderOptions);

            for (uint entryI = 0; entryI < entriesToRemove.Count; entryI++)
            {
                var currentEntryToRemove = entriesToRemove[(int)entryI];
                dat.RemoveEntry(currentEntryToRemove.Category, currentEntryToRemove.Entry);
            }

            _datSaver.Save(dat, datSaverOptions);
        }
예제 #4
0
 public EnvCryptDat Load(TOptions options)
 {
     return(_cachedResult ?? (_cachedResult = _toDecorate.Load(options)));
 }