Example #1
0
 public void loadMainStaff()
 {
     rsafile = new RSA_File_manager();
     panel1.Controls.Add(rsafile);
     panel2.Hide();
     rsafile.Show();
     dt = new DecryptText();
     panel1.Controls.Add(dt);
     dt.Hide();
     serverm = new ServerMonitor();
     panel1.Controls.Add(serverm);
     serverm.Hide();
 }
        public void SymmetricAlgorithmsDecryptionMatchesWithSecureString(SymmetricAlgorithms enumValue)
        {
            string       toProcess       = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ";
            SecureString keySecureString = TestingHelper.StringToSecureString("{>@#F09\0");

            byte[] algorithmBytes = CryptographyHelper.EncryptData(enumValue, Encoding.Unicode.GetBytes(toProcess), Encoding.Unicode.GetBytes(TestingHelper.SecureStringToString(keySecureString)));

            DecryptText symmetricAlgorithm = new DecryptText
            {
                Algorithm = enumValue,
                Encoding  = new InArgument <Encoding>(ExpressionServices.Convert((env) => System.Text.Encoding.Unicode))
            };

            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments.Add(nameof(DecryptText.Input), Convert.ToBase64String(algorithmBytes));
            arguments.Add(nameof(DecryptText.KeySecureString), keySecureString);

            WorkflowInvoker invoker        = new WorkflowInvoker(symmetricAlgorithm);
            string          activityString = (string)invoker.Invoke(arguments)[nameof(symmetricAlgorithm.Result)];

            Assert.Equal(toProcess, activityString);
        }
Example #3
0
        public void SymmetricAlgorithmsDecryptionMatches(SymmetricAlgorithms enumValue)
        {
            string toProcess = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ";
            string key       = "{>@#F09\0";

            byte[] algorithmBytes = CryptographyHelper.EncryptData(enumValue, Encoding.Unicode.GetBytes(toProcess), Encoding.Unicode.GetBytes(key));

            DecryptText symmetricAlgorithm = new DecryptText
            {
                Algorithm = enumValue,
                Encoding  = new VisualBasicValue <Encoding>(typeof(Encoding).FullName + "." + nameof(Encoding.Unicode))
            };

            Dictionary <string, object> arguments = new Dictionary <string, object>();

            arguments.Add(nameof(DecryptText.Input), Convert.ToBase64String(algorithmBytes));
            arguments.Add(nameof(DecryptText.Key), key);

            WorkflowInvokerTest invoker = new WorkflowInvokerTest(symmetricAlgorithm);
            string activityString       = (string)invoker.TestActivity(arguments)[nameof(symmetricAlgorithm.Result)];

            Assert.Equal(toProcess, activityString);
        }
        public static int RunDecrypt(Options.Decrypt DecryptOptions)
        {
            int           inError    = 0;
            StringBuilder errMsgText = new StringBuilder();

            if (DecryptOptions.EncryptedString == null)
            {
                DecryptOptions.EncryptedString = string.Empty;
            }
            if (DecryptOptions.EncryptedTextFile == null)
            {
                DecryptOptions.EncryptedTextFile = string.Empty;
            }

            if (DecryptOptions.EncryptedString.Length > 0 && DecryptOptions.EncryptedTextFile.Length > 0)
            {
                // Cannot use string and file at the same time.
                inError++;
                errMsgText.Append($"- Using both --encryptedstring and --encryptedfile options together is not supported");
            }

            if (DecryptOptions.EncryptedString.Length == 0 && DecryptOptions.EncryptedTextFile.Length == 0)
            {
                inError++;
                errMsgText.Append($"- Either --encryptedstring or --encryptedfile option must be provided.");
            }

            if (DecryptOptions.EncryptedString.Length == 0 && DecryptOptions.EncryptedTextFile.Length > 0)
            {
                if (!File.Exists(DecryptOptions.EncryptedTextFile))
                {
                    inError++;
                    errMsgText.Append($"- Provided encrypted text file, {DecryptOptions.EncryptedTextFile}, doesn't exist.");
                }
            }

            if (inError > 0)
            {
                Console.Write($"\nThere is a problem with provided parameters (--help for help):\n\n{errMsgText.ToString()}\n");
            }

            string valueToDecrypt;

            if (DecryptOptions.EncryptedTextFile.Length > 0)
            {
                try
                {
                    valueToDecrypt = File.ReadAllText(DecryptOptions.EncryptedTextFile);
                }
                catch (UnauthorizedAccessException)
                {
                    Console.Write($"- Error reading encrypted text file, unauthorized.\n");
                    return(201);
                }
                catch (DirectoryNotFoundException)
                {
                    Console.Write($"- Eror reading encrypted text file, Directory not found!\n");
                    return(202);
                }
                catch (Exception ex)
                {
                    Console.Write($"- An unknown error has occurred:\n\n{ex.Message}\n\n");
                    return(210);
                }
            }
            else if (DecryptOptions.EncryptedString.Length > 0)
            {
                valueToDecrypt = DecryptOptions.EncryptedString;
            }
            else
            {
                Console.Write($"- EncryptedString and EncryptedTextFile are empty. We shouldn't be here, must be missing a check!");
                return(211);
            }

            string result;

            try
            {
                result = DecryptText.Decrypt(valueToDecrypt);
            } catch (Exception ex)
            {
                Console.Write($"- Error while decrypting string:\n\n{ex.Message}\n\n");
                return(212);
            }
            Console.Write(result);
            return(0);
        }
Example #5
0
        private void MenuDecryptTextClicked(object sender, EventArgs e)
        {
            var decryptText = new DecryptText();

            AddPanel(decryptText);
        }