Пример #1
0
        public void ECBTest(string fileIn, string encFileOut, string decFileOut)
        {
            var key = DESUtility.GenerateKey();
            var des = new DESUtility(CipherMode.ECB, key);

            Assert.That(() => des.EncryptData(fileIn), Throws.Nothing);
            Assert.That(() => des.DecryptData(encFileOut), Throws.Nothing);
            var h1 = MD5(fileIn);
            var h2 = MD5(decFileOut);

            Assert.That(h1.Equals(h2));
        }
Пример #2
0
        public void CBCTest(string fileIn, string encFileOut, string decFileOut)
        {
            var key = DESUtility.GenerateKey();
            var des = new DESUtility(CipherMode.CBC, key);

            des.EncryptData(fileIn);
            des.DecryptData(encFileOut);
            var h1 = MD5(fileIn);
            var h2 = MD5(decFileOut);

            Assert.That(h1.Equals(h2));
        }
Пример #3
0
        public static void Main(string[] args)
        {
            DESUtility des;

            CommandLine.Parser.Default.ParseArguments <EncryptOptions, DecryptOptions>(args)
            .MapResult(
                (EncryptOptions opts) =>
            {
                var isModeCBC = opts.Mode.Equals(CipherMode.CBC.ToString());
                des           = new DESUtility(isModeCBC ? CipherMode.CBC : CipherMode.ECB, opts.Key);
                des.EncryptData(opts.InputFile);
                return(0);
            },
                (DecryptOptions opts) =>
            {
                var isModeCBC = opts.Mode.Equals(CipherMode.CBC.ToString());
                des           = new DESUtility(isModeCBC ? CipherMode.CBC : CipherMode.ECB, opts.Key);
                des.DecryptData(opts.InputFile);
                return(0);
            },
                errs => 1);
        }