Esempio n. 1
0
        public static void SetAppConfigValue(string XPathQuery, string value, string filename, bool cryptValue)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(filename);
            }
            catch
            {
                Console.Write("Can't find " + filename);
            }

            try
            {
                XmlElement itemTitle = (XmlElement)doc.SelectSingleNode(XPathQuery);
                string     val       = "";
                if (crypt == true & cryptValue == true)
                {
                    val = BlockEncrypter.EncryptStringBlock(value, Encoding.ASCII.GetBytes("Pa55w0rd"));
                }
                else
                {
                    val = value;
                }
                itemTitle.Attributes["value"].Value = val;
            }
            catch
            {
                Console.Write("Can't add " + value + " to " + XPathQuery + " in " + filename);
            }

            doc.Save(filename);
            ConfigurationManager.RefreshSection("appSettings");
            //Console.Write("Saving " + filename);
        }
Esempio n. 2
0
 /// <summary>
 /// Encrypts a plaintext string using the BlockEncrypter library.
 /// </summary>
 /// <param name="plaintext"></param>
 /// <returns></returns>
 public static string Encrypt(string plaintext)
 {
     return(BlockEncrypter.EncryptStringBlock(plaintext, Encoding.ASCII.GetBytes(ApplicationSettings.EncryptionKey)));
 }