public XmlElement DecryptSingleElementByKeyNumber(int encryptedKeyNumber)
        {
            EncryptedKey encryptedKey = new EncryptedKey();

            encryptedKey.LoadXml((XmlElement)this._encryptedKeyElements[encryptedKeyNumber]);
            ReferenceList      referenceList      = encryptedKey.ReferenceList;
            EncryptedReference encryptedReference = referenceList.Item(0);
            string             uri     = encryptedReference.Uri;
            KeyInfo            keyInfo = encryptedKey.KeyInfo;

            this._referenceList.Clear();
            ArrayList referenceElementList = new ArrayList();

            referenceElementList = this.FindXmlElementByURI(uri, this._tempdocument.ChildNodes[1]);
            XmlElement keyInfoElement = this._tempdocument.CreateElement("KeyInfo", SignedXml.XmlDsigNamespaceUrl);

            keyInfoElement.AppendChild(_tempdocument.ImportNode((XmlNode)encryptedKey.GetXml(), true));
            XmlElement encryptedDataElement   = (XmlElement)referenceElementList[0];
            RSACryptoServiceProvider provider = this._webService.RSACryptoServiceProvider;
            EncryptedXml             encXml   = new EncryptedXml(this._tempdocument);

            encXml.AddKeyNameMapping("Web Service Public Key", provider);
            EncryptedData data = new EncryptedData();

            data.LoadXml((XmlElement)encryptedDataElement);
            SymmetricAlgorithm algo = SymmetricAlgorithm.Create();

            algo.Key = encXml.DecryptEncryptedKey(encryptedKey);
            byte[] t = encXml.DecryptData(data, algo);
            encXml.ReplaceData(encryptedDataElement, t);
            this._tempdocument.GetElementsByTagName("wsse:Security")[0].RemoveChild(_tempdocument.GetElementsByTagName("xenc:EncryptedKey")[0]);
            XmlElement root = (XmlElement)this._decryptedDataList[encryptedKeyNumber];

            return((XmlElement)root);
        }
        private string DercryptSingleXmlElement(XmlElement encryptedKeyElement)
        {
            EncryptedKey encryptdKey = new EncryptedKey();

            encryptdKey.LoadXml(encryptedKeyElement);
            ReferenceList      referenceList      = encryptdKey.ReferenceList;
            EncryptedReference encryptedReference = referenceList.Item(0);
            string             uri     = encryptedReference.Uri;
            KeyInfo            keyInfo = encryptdKey.KeyInfo;

            this._referenceList.Clear();
            ArrayList  referenceElementList = this.FindXmlElementByURI(uri, this._inputDocument.ChildNodes[1]);
            XmlElement keyInfoElement       = this._inputDocument.CreateElement("KeyInfo", SignedXml.XmlDsigNamespaceUrl);

            keyInfoElement.AppendChild(encryptedKeyElement);
            if (referenceElementList.Count > 0)
            {
                XmlElement encryptedDataElement   = (XmlElement)referenceElementList[0];
                RSACryptoServiceProvider provider = this._webService.RSACryptoServiceProvider;
                XmlDocument doc  = new XmlDocument();
                XmlElement  root = doc.CreateElement("root");
                root.AppendChild(doc.ImportNode((XmlNode)encryptedKeyElement, true));
                root.AppendChild(doc.ImportNode(encryptedDataElement, true));
                doc.AppendChild(root);
                EncryptedXml encxml2 = new EncryptedXml(doc);
                EncryptedKey encKey2 = new EncryptedKey();
                encKey2.LoadXml((XmlElement)doc.GetElementsByTagName("xenc:EncryptedKey")[0]);
                EncryptedData encData2        = new EncryptedData();
                EncryptedData encDataElement2 = new EncryptedData();
                XmlElement    data2           = (XmlElement)doc.GetElementsByTagName("xenc:EncryptedData")[0];
                encDataElement2.LoadXml((XmlElement)doc.GetElementsByTagName("xenc:EncryptedData")[0]);
                encxml2.AddKeyNameMapping("Web Service Public Key", provider);
                SymmetricAlgorithm algo2 = SymmetricAlgorithm.Create();
                algo2.Key = encxml2.DecryptEncryptedKey(encKey2);
                byte[] t2 = encxml2.DecryptData(encDataElement2, algo2);
                encxml2.ReplaceData(data2, t2);
                doc.GetElementsByTagName("root")[0].RemoveChild(doc.GetElementsByTagName("xenc:EncryptedKey")[0]);
                this._tracer.appendDecryptedData(uri, doc.FirstChild.InnerXml);
                EncryptedXml encXml = new EncryptedXml(this._inputDocument);
                encXml.AddKeyNameMapping("Web Service Public Key", provider);
                EncryptedData data = new EncryptedData();
                data.LoadXml((XmlElement)encryptedDataElement);
                SymmetricAlgorithm algo = SymmetricAlgorithm.Create();
                algo.Key = encXml.DecryptEncryptedKey(encryptdKey);
                byte[] t = encXml.DecryptData(data, algo);
                encXml.ReplaceData(encryptedDataElement, t);
                this._encryptedDataList.Add(encryptedDataElement);
                this._decryptedDataList.Add(doc.GetElementsByTagName("root")[0]);
                this._encryptedKeyElements.Add(encryptedKeyElement);
                string decryptedXmlString;
                return(decryptedXmlString = Convert.ToBase64String(t));
            }
            return(string.Empty);
        }