private void DecryptEncryptedGrants(XmlNodeList encryptedGrantList, IRelDecryptor decryptor) { XmlElement encryptionMethod = null; XmlElement keyInfo = null; XmlElement cipherData = null; EncryptionMethod encryptionMethodObj = null; KeyInfo keyInfoObj = null; CipherData cipherDataObj = null; for (int i = 0, count = encryptedGrantList.Count; i < count; i++) { encryptionMethod = encryptedGrantList[i].SelectSingleNode("//r:encryptedGrant/enc:EncryptionMethod", _namespaceManager) as XmlElement; keyInfo = encryptedGrantList[i].SelectSingleNode("//r:encryptedGrant/dsig:KeyInfo", _namespaceManager) as XmlElement; cipherData = encryptedGrantList[i].SelectSingleNode("//r:encryptedGrant/enc:CipherData", _namespaceManager) as XmlElement; if ((encryptionMethod != null) && (keyInfo != null) && (cipherData != null)) { encryptionMethodObj = new EncryptionMethod(); keyInfoObj = new KeyInfo(); cipherDataObj = new CipherData(); encryptionMethodObj.LoadXml(encryptionMethod); keyInfoObj.LoadXml(keyInfo); cipherDataObj.LoadXml(cipherData); MemoryStream toDecrypt = null; Stream decryptedContent = null; StreamReader streamReader = null; try { toDecrypt = new MemoryStream(cipherDataObj.CipherValue); decryptedContent = _relDecryptor.Decrypt(encryptionMethodObj, keyInfoObj, toDecrypt); if ((decryptedContent == null) || (decryptedContent.Length == 0)) { throw new CryptographicException(SR.Cryptography_Xml_XrmlUnableToDecryptGrant); } streamReader = new StreamReader(decryptedContent); string clearContent = streamReader.ReadToEnd(); encryptedGrantList[i].ParentNode.InnerXml = clearContent; } finally { if (toDecrypt != null) { toDecrypt.Close(); } if (decryptedContent != null) { decryptedContent.Close(); } if (streamReader != null) { streamReader.Close(); } } encryptionMethodObj = null; keyInfoObj = null; cipherDataObj = null; } encryptionMethod = null; keyInfo = null; cipherData = null; } }