예제 #1
0
        //Selector function (Menu)
        public List <string> SelectEncryption(string choice, string msg)
        {
            byte[] key;
            byte[] iv;
            byte[] encMsg;
            byte[] decMsg;


            switch (choice)
            {
            //DEC
            //Selects and uses DES encryption
            case "1":
                key = RandomNumberGenerator(8);
                iv  = RandomNumberGenerator(8);

                encWatch.Start();
                encMsg = encryptor.DESEncrypt(msg, key, iv);
                encWatch.Stop();
                decWatch.Start();
                decMsg = decryptor.DESDecrypt(encMsg, key, iv);
                decWatch.Start();

                return(ReturnStrings(key, iv, encMsg, decMsg, encWatch, decWatch));

            //TripleDES
            //Selects and uses TripleDES encryption
            case "2":
                key = RandomNumberGenerator(24);
                iv  = RandomNumberGenerator(8);
                encWatch.Start();
                encMsg = encryptor.TripleDESEncrypt(msg, key, iv);
                encWatch.Stop();
                decWatch.Start();
                decMsg = decryptor.TripleDESDecrypt(encMsg, key, iv);
                decWatch.Stop();

                return(ReturnStrings(key, iv, encMsg, decMsg, encWatch, decWatch));

            //AES
            //Selects and uses AES encryption
            case "3":
                key = RandomNumberGenerator(32);
                iv  = RandomNumberGenerator(16);
                encWatch.Start();
                encMsg = encryptor.AESEncrypt(msg, key, iv);
                encWatch.Stop();
                decWatch.Start();
                decMsg = decryptor.AESDecrypt(encMsg, key, iv);
                decWatch.Start();

                return(ReturnStrings(key, iv, encMsg, decMsg, encWatch, decWatch));

            //Default Nothing Happens.
            default:
                return(null);
            }
        }