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(); EncryptedData ed = new EncryptedData();
// Specify the namespace URI for XML encryption elements. // 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. // Specify the namespace URI for the TrippleDES algorithm.
ed.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl); ed.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl);
@ -96,11 +96,23 @@ namespace EduNetworkBuilder
EncryptedXml.ReplaceElement(inputElement, ed, false); 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 object.
XmlElement encryptedElement = docValue.GetElementsByTagName("EncryptedData")[0] as XmlElement; XmlElement encryptedElement = ChooseBestElement(preferType);
// If the EncryptedData element was not found, throw an exception. // If the EncryptedData element was not found, throw an exception.
if (encryptedElement == null) if (encryptedElement == null)