Changes to allow encryption

This commit is contained in:
Tim Young 2017-08-09 15:32:04 -05:00
parent b6bcd7aff2
commit 3136228e76
1 changed files with 15 additions and 3 deletions

View File

@ -81,7 +81,7 @@ namespace EduNetworkBuilder
EncryptedData ed = new EncryptedData();
// Specify the namespace URI for XML encryption elements.
ed.Type = EncryptedXml.XmlEncElementUrl;
ed.Type = Element + " " + EncryptedXml.XmlEncElementUrl;
// Specify the namespace URI for the TrippleDES algorithm.
ed.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl);
@ -96,11 +96,23 @@ namespace EduNetworkBuilder
EncryptedXml.ReplaceElement(inputElement, ed, false);
}
public void Decrypt()
XmlElement ChooseBestElement(string preferType)
{
XmlNodeList xnl = docValue.GetElementsByTagName("EncryptedData");
foreach (XmlElement one in xnl.OfType<XmlElement>())
{
string TypeAttr = one.GetAttribute("Type");
if (TypeAttr != null && TypeAttr.StartsWith(preferType))
return one;
}
return xnl[0] as XmlElement;
}
public void Decrypt(string preferType)
{
// XmlElement object.
XmlElement encryptedElement = docValue.GetElementsByTagName("EncryptedData")[0] as XmlElement;
XmlElement encryptedElement = ChooseBestElement(preferType);
// If the EncryptedData element was not found, throw an exception.
if (encryptedElement == null)