Пример #1
0
        private bool ProcessEncryptedDataItem(XmlElement encryptedDataElement)
        {
            // first see whether we want to ignore this one
            if (ExceptUris.Count > 0)
            {
                for (int index = 0; index < ExceptUris.Count; index++)
                {
                    if (IsTargetElement(encryptedDataElement, (string)ExceptUris[index]))
                    {
                        return(false);
                    }
                }
            }
            EncryptedData ed = new EncryptedData();

            ed.LoadXml(encryptedDataElement);
            SymmetricAlgorithm symAlg = EncryptedXml.GetDecryptionKey(ed, null);

            if (symAlg == null)
            {
                throw new CryptographicException(SR.Cryptography_Xml_MissingDecryptionKey);
            }
            byte[] decrypted = EncryptedXml.DecryptData(ed, symAlg);

            ReplaceEncryptedData(encryptedDataElement, decrypted);
            return(true);
        }
Пример #2
0
        public override object GetOutput()
        {
            XmlDocument document;

            if (inputObj is Stream)
            {
                document = new XmlDocument();
                document.PreserveWhitespace = true;
                document.XmlResolver        = GetResolver();
                document.Load(new XmlSignatureStreamReader(
                                  new StreamReader(inputObj as Stream)));
            }
            else if (inputObj is XmlDocument)
            {
                document = inputObj as XmlDocument;
            }
            else
            {
                throw new NullReferenceException();
            }

            XmlNodeList nodes = document.GetElementsByTagName("EncryptedData", EncryptedXml.XmlEncNamespaceUrl);

            foreach (XmlNode node in nodes)
            {
                if (node == document.DocumentElement && exceptUris.Contains("#xpointer(/)"))
                {
                    break;
                }

                // Need to exclude based on ExceptURI.  Only accept #id references.
                foreach (string uri in exceptUris)
                {
                    if (IsTargetElement((XmlElement)node, uri.Substring(1)))
                    {
                        break;
                    }
                }

                EncryptedData encryptedData = new EncryptedData();
                encryptedData.LoadXml((XmlElement)node);
                SymmetricAlgorithm symAlg = EncryptedXml.GetDecryptionKey(encryptedData, encryptedData.EncryptionMethod.KeyAlgorithm);
                EncryptedXml.ReplaceData((XmlElement)node, EncryptedXml.DecryptData(encryptedData, symAlg));
            }

            return(document);
        }
Пример #3
0
		public void GetDecryptionKey_StringNull ()
		{
			EncryptedXml ex = new EncryptedXml ();
			Assert.IsNull (ex.GetDecryptionKey (new EncryptedData (), null));
		}
Пример #4
0
		public void GetDecryptionKey_EncryptedDataNull ()
		{
			EncryptedXml ex = new EncryptedXml ();
			ex.GetDecryptionKey (null, EncryptedXml.XmlEncAES128Url);
		}