예제 #1
0
파일: CipherFactory.cs 프로젝트: radtek/kit
        public static ICipher GetCipher(AlgorithmKind kind, CipherOptions options)
        {
            ICipher cipher;

            switch (kind)
            {
            case AlgorithmKind.AES:
                cipher = new Cipher(Aes.Create())
                {
                    Options = options
                };
                break;

            case AlgorithmKind.TripleDES:
                cipher = new Cipher(TripleDES.Create())
                {
                    Options = options
                };
                break;

            default:
                throw new NotSupportedException("Unknown algorithm");
            }

            return(cipher);
        }
 public SourceTask(int iterationCount, CipherOptions opt, string TableName, MultiThreadTest <PermutationDiffusionTestx5.SourceTask> task)
 {
     this.TableName      = TableName;
     this.IterationCount = iterationCount;
     this.options        = opt;
     this.task           = task;
 }
예제 #3
0
        private void RecordEntry(string filePath, string fileEvent)
        {
            ArchiveOptions archiveOptions = optionsManager.GetOptions <ArchiveOptions>(this) as ArchiveOptions;
            CipherOptions  cipherOptions  = optionsManager.GetOptions <CipherOptions>(this) as CipherOptions;
            string         encrypted;
            FileInfo       file = new FileInfo(filePath);
            string         td   = $"{targetDirectory}\\{file.LastWriteTime:yyyy\\\\MM\\\\dd}";

            string newName = $"Sales_{file.LastWriteTime:yyyy_MM_dd_HH_mm_ss}";
            int    i       = 0;

            while (File.Exists($"{td}\\{newName}.txt"))
            {
                i++;
                newName = $"{Path.GetFileNameWithoutExtension(filePath)}({i})_{file.LastWriteTime:yyyy_MM_dd_HH_mm_ss}";
            }
            if (!Directory.Exists(td))
            {
                Directory.CreateDirectory(td);
            }
            Log($"File {newName} {fileEvent}", true, logFile);
            using (StreamReader sr = new StreamReader(filePath))
            {
                encrypted = Cypher.Encrypt(sr.ReadToEnd(), cipherOptions.EncrypterKey);
            }
            using (StreamWriter sw = new StreamWriter(filePath))
            {
                sw.Write(encrypted);
            }
            string newPath = $"{td}\\{newName}";

            try
            {
                Archivate.Compress(filePath, newPath + ".gz", archiveOptions.CompressionLevel);
                Archivate.Compress(filePath, $"{archiveDirectory}\\{newName}.gz", archiveOptions.CompressionLevel);
                Archivate.Decompress(newPath + ".gz", newPath + ".txt");
            }
            catch (Exception ex)
            {
                Log($"Fatal error ocured while compressing - {ex}", true, logFile);
                return;
            }
            File.Delete(filePath);
            File.Delete(newPath + ".gz");
            using (StreamReader sr = new StreamReader(newPath + ".txt"))
            {
                encrypted = sr.ReadToEnd();
            }
            using (StreamWriter sw = new StreamWriter(newPath + ".txt"))
            {
                sw.Write(Cypher.Decrypt(encrypted, cipherOptions.EncrypterKey));
            }
            Log($"File {newName} sent successfully", true, logFile);
        }
            public override IEnumerable <SourceTask> GetIterator()
            {
                foreach (var opt in /*CipherOptions.getAllNotEmptyCiphers()*/ CipherOptions.getKeccakCipher())
                {
                    // 6 минут на 1 раунд keccak
                    foreach (int i in new int[] { 8 /*, 12, 15*/ })
                    {
                        yield return(new SourceTask(i, opt, "transpose128", this.task));

                        /*yield return new SourceTask(i, opt, "transpose200");
                        *  yield return new SourceTask(i, opt, "transpose256");
                        *  yield return new SourceTask(i, opt, "transpose384");
                        *  yield return new SourceTask(i, opt, "transpose387");*/
                    }
                }
            }
예제 #5
0
            public override IEnumerable <SourceTask> GetIterator()
            {
                foreach (var opt in CipherOptions.getAllNotEmptyCiphers())
                {
                    for (int i = 2; i <= 8; i++)
                    {
                        /*yield return new SourceTask(i, opt, "base131");
                        *  yield return new SourceTask(i, opt, "base199");
                        *  yield return new SourceTask(i, opt, "base211");
                        *  yield return new SourceTask(i, opt, "base233");*/
                        yield return(new SourceTask(i, opt, "transpose128"));

                        yield return(new SourceTask(i, opt, "transpose200"));

                        /*yield return new SourceTask(i, opt, "transpose256");
                        *  yield return new SourceTask(i, opt, "transpose384");
                        *  yield return new SourceTask(i, opt, "transpose387");*/
                    }
                }
            }
예제 #6
0
 public SourceTask(int iterationCount, CipherOptions opt, string TableName)
 {
     this.TableName      = TableName;
     this.IterationCount = iterationCount;
     this.options        = opt;
 }