Ejemplo n.º 1
0
        public void __init()
        {
            testConfig = new SimpleAesEncryptionConfiguration();
            testConfig.EncryptionKey = new EncryptionKeyConfigurationElement(256, "3q2+796tvu/erb7v3q2+796tvu/erb7v3q2+796tvu8=");

            _target = new RijndaelMessageDecryptor(testConfig);
        }
Ejemplo n.º 2
0
        public void ParameterlessConstructor_ConfigRetrievedFromConfigFile_ConfigCanBeAccessed()
        {
            var target = new RijndaelMessageDecryptor();

            Assert.IsNotNull(target.Configuration);
            Assert.AreEqual("TestKey", target.Configuration.EncryptionKey.Key); // NB: retrieved from the App.config file
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Decrypts the log.
        /// </summary>
        /// <param name="options">The options to use for decrypting the log.</param>
        public void DecryptLog(LogDecryptOptions options)
        {
            options.OutputPath = GenerateOutputPath(options);

            var encryptionConfiguration = GenerateEncryptionConfiguration(options);
            var decryptor = new RijndaelMessageDecryptor(encryptionConfiguration);

            using (var outputStream = new StreamWriter(options.OutputPath, true))
            {
                var lines = FileHelper.ReadLines(options.InputPath);
                foreach (string line in lines)
                {
                    if (line.Contains(RijndaelMessageHandler.CYPHER_TEXT_IV_SEPERATOR))
                    {
                        // Split the line by spaces, tabs
                        var tokens            = line.Split(new[] { " ", "\t", ">", "<" }, StringSplitOptions.RemoveEmptyEntries);
                        var decryptionTargets = tokens.Where(x => x.Contains(RijndaelMessageHandler.CYPHER_TEXT_IV_SEPERATOR));
                        var decryptionPairs   = decryptionTargets.Select(x => new Tuple <string, string>(x, decryptor.Decrypt(x)));

                        // Replace any encrypted strings in the line and then output it to the file
                        var output = decryptionPairs.Aggregate(line, (current, pair) => current.Replace(pair.Item1, pair.Item2));
                        outputStream.WriteLine(output);
                    }
                    else
                    {
                        // Output the unmodified line
                        outputStream.WriteLine(line);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void ConstructorWithConfig_ConfigStoredInCorrectProperty_ConfigCanBeAccessed()
        {
            var localTestConfig = new SimpleAesEncryptionConfiguration();

            localTestConfig.EncryptionKey = new EncryptionKeyConfigurationElement(256, "3q2+796tvu/erb7v3q2+796tvu/erb7v3q2+796tvu8=");

            var target = new RijndaelMessageDecryptor(localTestConfig);

            Assert.AreSame(localTestConfig, target.Configuration);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var input = "Hello World!";

            if (args.Length > 0)
            {
                input = args[0];
            }

            var encryptor  = new RijndaelMessageEncryptor();
            var cyphertext = encryptor.Encrypt(input);

            var decryptor = new RijndaelMessageDecryptor();
            var plaintext = decryptor.Decrypt(cyphertext);

            Console.WriteLine("Input:" + input);
            Console.WriteLine("Cyphertext:" + cyphertext);
            Console.WriteLine("Plaintext:" + plaintext);

            Console.WriteLine();
            Console.WriteLine("Please press any key to exit.");
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="listConfig"></param>
        /// <param name="dte"></param>
        /// <param name="dtagrid"></param>

        public List<String> getListData(ListConfig listConfig, DateTime dte, DataGridView dtagrid, String EmailMgetFileName, Boolean sendTestEmails)
        {

            SP.List oList = _context.Web.Lists.GetByTitle(listConfig._SharePointSListName);
            List<String> sentRecipients = new List<string>();
            CamlQuery camlQuery = new CamlQuery();
            Boolean canceled = false;
            if (dtagrid != null)
            {// get all all data for testing
                camlQuery.ViewXml = "<View><Query><Where><Geq>" +
                    "<FieldRef Name='ID'/>" +
                    "<Value Type='Number'>0</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
            }
            else
            {

                camlQuery.ViewXml = "<View><Query><Where><And>";
                foreach (String af in listConfig._ActiveFields)
                    camlQuery.ViewXml += "<Eq><FieldRef Name='" + af + "'/><Value Type='Bool'>True</Value></Eq>";
                camlQuery.ViewXml += "</And></Where></Query></View>";

            }
            if (listConfig._CAMLQUery != null && !listConfig._CAMLQUery.Equals(""))// over ride the query if user types it.
                camlQuery.ViewXml = "<View><Query><Where>" + listConfig._CAMLQUery + "</Where></Query></View>";


            ListItemCollection collListItem = oList.GetItems(camlQuery);
            try
            {
                _context.Load(collListItem);
            }
            catch (Exception ex)
            {
                String Msg = @"[CAML Query " + camlQuery.ViewXml + " Failed:" + ex.Message + "]";
                if (dtagrid != null)
                    MessageBox.Show(ex.Message, "Error in CAML");
                else
                    throw new Exception(Msg, ex);
            }

            int activeFieldsCount = 0;
       //     if (dtagrid != null)
       //     {
                activeFieldsCount = setUpDataGrid(listConfig, dtagrid);

       //     }

            List siteAppList = _context.Web.Lists.GetByTitle(listConfig._SharePointSListName);
            // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll" 
            // so that it grabs all list items, regardless of the folder they are in. 
            try
            {
                _context.ExecuteQuery();
            }
            catch (Exception ex)
            {
                String Msg = @"[CAML Query " + camlQuery.ViewXml + " Failed:" + ex.Message + "]";
                if (dtagrid != null)
                    MessageBox.Show(ex.Message, "Error in CAML");
                else
                    throw new Exception(Msg, ex);
            }


            int Frequency = 7;
            String FrequencyDBValue = "";
            String[] activeFlags = new string[activeFieldsCount];
            Object[] objRow = new Object[activeFieldsCount];
            int emailDiagCount = 0;
            foreach (ListItem listItem in collListItem)
            {
                Dictionary<String, String> secondaryValues = getSecondaryListData(listConfig._secondaryListName, listItem[listConfig._joinFeeld]);
                //             Dictionary<String, String> secondaryValues = getSecondaryListData("Requests", listItem["RequestID"]);

                String emailAddress = "unknown";
                String emailName = "unknown";
                Object obj = listItem[listConfig._UserField];


                // go thru and figure out if the data is null.. then we have to either  default things and run..
                // or bail... architecureal decision
                if (listItem[listConfig._UserField] == null || listItem[listConfig._UserField].ToString().Length < 1)
                    continue;// no data to process
                int activeCount = 0;
                foreach (String af in listConfig._ActiveFields)
                {
                    if (listItem[af] == null)
                        activeFlags[activeCount++] = "False";
                    else
                        activeFlags[activeCount++] = listItem[af].ToString();
                }
                foreach (String af in listConfig._secondaryFields)
                {
                    activeFlags[activeCount++] = secondaryValues[af].ToString();
                }

                if (listItem[listConfig._FrequencyField] == null)
                    Frequency = 7;
                else
                {
                    try
                    {
                        SPFieldMultiChoiceValue choices = new SPFieldMultiChoiceValue(listItem[listConfig._FrequencyField].ToString());
                        if (choices.Count >= 1)
                        {
                            Frequency = Int32.Parse(listConfig._FrequecncyItems[choices[0]]);
                        }
                        FrequencyDBValue = choices[0];
                    }
                    catch (Exception ex)
                    {
                        Frequency = 7;
                    }
                }

                String dteField = listConfig._DateField;// "Created";


                if (listItem[listConfig._UserField] != null && listItem[listConfig._UserField].ToString().Length > 0)
                {
                    FieldUserValue UserName = (FieldUserValue)listItem[listConfig._UserField];
                    emailName = UserName.LookupValue;
                    emailAddress = getUserEmail(UserName);
                }
                String send = "Yes";
                Int32 interval = -1;


                if (dteField != null && listItem[dteField] != null)
                    interval = (DateTime.Parse(dte.ToString("d")) - DateTime.Parse(DateTime.Parse(listItem[dteField].ToString()).ToString("d"))).Days;// add one to make it inclusive of the day it ran on.
                else
                {
                    String Msg = @"[Date field  is NULL]";
                    if (dtagrid != null)
                        MessageBox.Show(Msg, "Error in Processing interval");
                    else
                        throw new Exception(Msg);
                }
                if (interval <= 0 || (interval % Frequency) != 0)
                    send = "No";

                int gridRowCount = 0;

                for (gridRowCount = 0; gridRowCount < activeCount; gridRowCount++)
                {
                    if (activeFlags[gridRowCount] == "False")
                        send = "No";
                }
                // We have all the list item data. 
                if (dtagrid != null)
                {
                    for (gridRowCount = 0; gridRowCount < activeCount; gridRowCount++)
                    {
                        objRow[gridRowCount] = activeFlags[gridRowCount];
                    }
                    objRow[gridRowCount++] = emailName + "<" + emailAddress + ">";
                    objRow[gridRowCount++] = FrequencyDBValue;
                    objRow[gridRowCount++] = interval;
                    objRow[gridRowCount++] = Frequency;
                    objRow[gridRowCount++] = String.Format("{0:MM/dd/yyyy}", dte);
                    objRow[gridRowCount++] = String.Format("{0:MM/dd/yyyy}", listItem[dteField]);
                    objRow[gridRowCount++] = send;
                    dtagrid.Rows.Add(objRow);

                }
                if (send.Equals("Yes"))
                {
                    bool tesetSend = true;
                    if( dtagrid != null)
                         tesetSend = false;
                    if (emailDiagCount++ < 50 && sendTestEmails)
                    {
                        try
                        {
                            String msg = String.Format("To:{0}\nFrom:{1}\nSubject:{2}\nBody:{3}\n",
                            emailAddress, listConfig._emailFrom,
                            replaceText(listConfig._emailSubject, listItem, listConfig._SharePointServerName, secondaryValues),
                            replaceText(listConfig._emailBody, listItem, listConfig._SharePointServerName, secondaryValues));
                            if (!canceled)
                            {
                                DialogResult dialogResult = MessageBox.Show(msg, "Review #" + emailDiagCount + " Ctrl C to copy - press Okay to send", MessageBoxButtons.YesNoCancel);
                                if (dialogResult == DialogResult.No)
                                {
                                    tesetSend = false;
                                }
                                if (dialogResult == DialogResult.Cancel)
                                {
                                    canceled = true;
                                    tesetSend = false;
                                }
                            }
                            else
                                tesetSend = false;
                        }
                        catch (Exception ex)
                        {
                            String Msg = @"[Email for " + emailAddress + " Failed:" + ex.Message + "]";
                            MessageBox.Show(ex.Message, "Error on " + emailAddress);
                        }
                    }
                    if (!EmailMgetFileName.Equals("") && tesetSend)
                    {
                        ServerManagement sm = getServerSetup(EmailMgetFileName);
                        try
                        {
                            var decryptor = new RijndaelMessageDecryptor();
                            SmtpClient client = new SmtpClient(sm._SMTPServerName);
                            //MailAddress from = new MailAddress(emailAddress, listConfig._emailFrom);
                            MailAddress from = new MailAddress(listConfig._emailFrom);
                            // Set destinations for the e-mail message.
                            MailAddress to = new MailAddress(emailAddress);
                            // Specify the message content.
                            MailMessage message = new MailMessage(from, to);
                            message.IsBodyHtml = true;
                            message.Body = replaceText(listConfig._emailBody, listItem, listConfig._SharePointServerName, secondaryValues);
                            message.BodyEncoding = System.Text.Encoding.UTF8;
                            message.Subject = replaceText(listConfig._emailSubject, listItem, listConfig._SharePointServerName, secondaryValues);
                            message.SubjectEncoding = System.Text.Encoding.UTF8;
                            client.Credentials = new System.Net.NetworkCredential(sm._SMTPUserId, decryptor.Decrypt(sm._SMTPPwd));
                            client.Port = Int32.Parse(sm._SMTPPort);
                            client.Send(message);
                            sentRecipients.Add(emailAddress);
                            Console.WriteLine("Email sent for " + to);
                            Console.WriteLine("Subject Line " + message.Subject);
                        }
                        catch (Exception ex)
                        {
                            String Msg = @"[Email for " + emailAddress + " Failed:" + ex.Message + "]";
                            throw new Exception(Msg, ex);
                        }
                    }

                }
            }      /// 
            return sentRecipients;
        }
Ejemplo n.º 7
0
        public static string Decrypt(this string value)
        {
            var decryptor = new RijndaelMessageDecryptor();

            return(decryptor.Decrypt(value));
        }