public static void DecryptElement(XmlElement encryptedElement, string password)
 {
     RijndaelWrapper wrapper = new RijndaelWrapper(password);
     EncryptedData data = new EncryptedData();
     data.LoadXml(encryptedElement);
     EncryptedXml result = new EncryptedXml();
     byte[] decrypted = result.DecryptData(data, wrapper.SymmetricAlgorithm);
     result.ReplaceData(encryptedElement, decrypted);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        /// <param name="password"></param>
        /// <param name="content">true to replace content, false to replace entire element</param>
        public static void EncryptElement(XmlElement element, string password, bool content)
        {
            XmlDocument doc = element.OwnerDocument;
            EncryptedXml eXml = new EncryptedXml(doc);

            RijndaelWrapper wrapper = new RijndaelWrapper(password);
            byte[] cipherText = eXml.EncryptData((XmlElement)doc.FirstChild.FirstChild, wrapper.SymmetricAlgorithm, content);
            EncryptedData data = new EncryptedData();
            data.EncryptionMethod = new EncryptionMethod(wrapper.Url);
            data.CipherData = new CipherData(cipherText);
            data.KeyInfo = new KeyInfo();
            EncryptedXml.ReplaceElement(element, data, content);
        }
Esempio n. 3
0
 public static void DecryptElement(XmlNode encryptedNode, string password)
 {
     RijndaelWrapper wrapper = new RijndaelWrapper(password);
     string cipherXml = encryptedNode.InnerXml;
     int begin = cipherXml.IndexOf(TAG_BEGIN) + TAG_BEGIN.Length;
     int end = cipherXml.IndexOf(TAG_END);
     string wholeSheBangString = cipherXml.Substring(begin, end - begin);
     byte[] wholeShebang = EncryptionUtil.GetBytesFromBase64String(wholeSheBangString);
     byte[] iv = new byte[wrapper.SymmetricAlgorithm.IV.Length];
     byte[] cipherText = new byte[wholeShebang.Length - iv.Length];
     Array.Copy(wholeShebang, iv, iv.Length);
     Array.Copy(wholeShebang,iv.Length, cipherText, 0,wholeShebang.Length - iv.Length);
     string plainXml = EncryptionUtil.GetString(wrapper.DecryptMessage(cipherText, iv));
     IsLegalXmlText(plainXml);
     encryptedNode.ParentNode.InnerXml = plainXml;
 }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        /// <param name="password"></param>
        /// <param name="content">true to replace content, false to replace entire element</param>
        public static void EncryptElement(XmlNode element, string password, bool content)
        {
            RijndaelWrapper wrapper = new RijndaelWrapper(password);
            byte[] cipherXml;
            if (!content)
                cipherXml = wrapper.EncryptMessage(EncryptionUtil.GetBytes(element.OuterXml));
            else
                cipherXml = wrapper.EncryptMessage(EncryptionUtil.GetBytes(element.InnerXml));
            byte[] iv = wrapper.SymmetricAlgorithm.IV;
            byte[] wholeShebang = new byte[cipherXml.Length + iv.Length];
            iv.CopyTo(wholeShebang, 0);
            cipherXml.CopyTo(wholeShebang, iv.Length);
            string encryptedMessage = EncryptionUtil.GetStringBase64(wholeShebang);

            string encryptedElementAsString = string.Format(ENCRYPTED_DATA_TEMPLATE,wrapper.Url);
            encryptedElementAsString = encryptedElementAsString.Replace(REPLACE_THIS, encryptedMessage);
            if (!content)
                element.ParentNode.InnerXml = encryptedElementAsString;
            else
            {
                element.InnerXml = encryptedElementAsString;
            }
        }