コード例 #1
0
 private IAlgorithm decryptFile(AlgorithmParams p)
 {
     return(decryptFile(p.Src, p.Dst, p.Password));
 }
コード例 #2
0
 private IAlgorithm encryptFile(AlgorithmParams p)
 {
     return(encryptFile(p.Src, p.Dst, p.CipherMode, p.SegmentSize, p.SessionKeySize, p.Password));
 }
コード例 #3
0
        /**
         * Проверка правильности
         */
        private void button1_Click_1(object sender, EventArgs e)
        {
            String path        = "E:\\Projekty\\BSK\\dane-testowe\\pattern.in";
            var    srcChecksum = computeFileChecksum(path);

            //System.Console.WriteLine("srcChecksum = {0}", srcChecksum);

            // создание списка параметров
            String encPath = "";
            String decPath = "";

            AlgorithmParams[] algParams = new AlgorithmParams[] {
                new AlgorithmParams(path, encPath, "ECB", 128, 256, "1234567890"),

                new AlgorithmParams(path, encPath, "CBC", 128, 128, ""),

                new AlgorithmParams(path, encPath, "CFB", 128, 128, "0987654321"),
                new AlgorithmParams(path, encPath, "CFB", 120, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 112, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 104, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 96, 128, "testtest"),
                new AlgorithmParams(path, encPath, "CFB", 88, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 80, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 72, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 64, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 56, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 48, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 40, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 32, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 24, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 16, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 8, 128, ""),

                new AlgorithmParams(path, encPath, "OFB", 128, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 120, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 112, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 104, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 96, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 88, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 80, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 72, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 64, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 56, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 48, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 40, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 32, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 24, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 16, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 8, 128, "")
            };

            // выполнение тестов
            Stopwatch sw = new Stopwatch();

            foreach (var p in algParams)
            {
                if (null == p)
                {
                    continue;
                }

                String testSignature = p.CipherMode + "/" + p.SegmentSize.ToString() + "/" + p.SessionKeySize.ToString();

                using (var alg = encryptFile(p))
                {
                    sw.Start();
                    alg.encrypt(Int64.MaxValue);
                    sw.Stop();
                }
                Console.WriteLine(testSignature + " encrypt time: {0}", sw.Elapsed);
                sw.Reset();


                p.Src = p.Dst;
                p.Dst = decPath;

                using (var alg = decryptFile(p))
                {
                    sw.Start();
                    alg.encrypt(Int64.MaxValue);
                    sw.Stop();
                }
                Console.WriteLine(testSignature + " decrypt time: {0}", sw.Elapsed);
                sw.Reset();

                var resultChecksum = computeFileChecksum(decPath);
                //System.Console.WriteLine("resultChecksum = {0}", resultChecksum);

                // сравнение исходного файла с результирующим
                if (srcChecksum != resultChecksum)
                {
                    MessageBox.Show("Неверный результат во время теста " + testSignature);

                    return;
                }
            }

            MessageBox.Show("OK");
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: rzymek01/bsk-serpent
 private IAlgorithm encryptFile(AlgorithmParams p)
 {
     return encryptFile(p.Src, p.Dst, p.CipherMode, p.SegmentSize, p.SessionKeySize, p.Password);
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: rzymek01/bsk-serpent
 private IAlgorithm decryptFile(AlgorithmParams p)
 {
     return decryptFile(p.Src, p.Dst, p.Password);
 }
コード例 #6
0
ファイル: Form1.cs プロジェクト: rzymek01/bsk-serpent
        /**
         * Testowanie poprawności
         */
        private void button1_Click_1(object sender, EventArgs e)
        {
            String path = "E:\\Projekty\\BSK\\dane-testowe\\pattern.in";
            var srcChecksum = computeFileChecksum(path);

            //System.Console.WriteLine("srcChecksum = {0}", srcChecksum);

            // utworzenie listy parametrów
            String encPath = "E:\\Projekty\\BSK\\dane-testowe\\pattern.enc";
            String decPath = "E:\\Projekty\\BSK\\dane-testowe\\pattern.dec";

            AlgorithmParams[] algParams = new AlgorithmParams[] {
                new AlgorithmParams(path, encPath, "ECB", 128, 256, "1234567890"),

                new AlgorithmParams(path, encPath, "CBC", 128, 128, ""),

                new AlgorithmParams(path, encPath, "CFB", 128, 128, "0987654321"),
                new AlgorithmParams(path, encPath, "CFB", 120, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 112, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 104, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 96, 128, "testtest"),
                new AlgorithmParams(path, encPath, "CFB", 88, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 80, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 72, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 64, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 56, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 48, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 40, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 32, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 24, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 16, 128, ""),
                new AlgorithmParams(path, encPath, "CFB", 8, 128, ""),

                new AlgorithmParams(path, encPath, "OFB", 128, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 120, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 112, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 104, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 96, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 88, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 80, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 72, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 64, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 56, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 48, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 40, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 32, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 24, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 16, 128, ""),
                new AlgorithmParams(path, encPath, "OFB", 8, 128, "")
            };

            // wykonanie testów
            Stopwatch sw = new Stopwatch();

            foreach (var p in algParams)
            {
                if (null == p)
                    continue;

                String testSignature = p.CipherMode + "/" + p.SegmentSize.ToString() + "/" + p.SessionKeySize.ToString();

                using (var alg = encryptFile(p))
                {
                    sw.Start();
                    alg.encrypt(Int64.MaxValue);
                    sw.Stop();
                }
                Console.WriteLine(testSignature + " encrypt time: {0}", sw.Elapsed);
                sw.Reset();

                p.Src = p.Dst;
                p.Dst = decPath;

                using (var alg = decryptFile(p))
                {
                    sw.Start();
                    alg.encrypt(Int64.MaxValue);
                    sw.Stop();
                }
                Console.WriteLine(testSignature + " decrypt time: {0}", sw.Elapsed);
                sw.Reset();

                var resultChecksum = computeFileChecksum(decPath);
                //System.Console.WriteLine("resultChecksum = {0}", resultChecksum);

                // porównanie pliku źródłowego z wynikowym
                if (srcChecksum != resultChecksum)
                {
                    MessageBox.Show("Niepoprawny wynik podczas testu " + testSignature);

                    return;
                }
            }

            MessageBox.Show("Wszystko OK");
        }