public static SmtpAddress Decrypt(XmlElement encryptedSharingKey, SymmetricSecurityKey symmetricSecurityKey) { XmlDocument xmlDocument = new SafeXmlDocument(); try { xmlDocument.AppendChild(xmlDocument.ImportNode(encryptedSharingKey, true)); } catch (XmlException) { SharingKeyHandler.Tracer.TraceError <string>(0L, "Unable to import XML element of sharing key: {0}", encryptedSharingKey.OuterXml); return(SmtpAddress.Empty); } EncryptedXml encryptedXml = new EncryptedXml(xmlDocument); encryptedXml.AddKeyNameMapping("key", symmetricSecurityKey.GetSymmetricAlgorithm("http://www.w3.org/2001/04/xmlenc#tripledes-cbc")); try { encryptedXml.DecryptDocument(); } catch (CryptographicException) { SharingKeyHandler.Tracer.TraceError <string>(0L, "Unable to decrypt XML element sharing key: {0}", encryptedSharingKey.OuterXml); return(SmtpAddress.Empty); } return(new SmtpAddress(xmlDocument.DocumentElement.InnerText)); }
public static XmlElement Decrypt(XmlElement xmlElement, SymmetricSecurityKey symmetricSecurityKey) { XmlDocument xmlDocument = new SafeXmlDocument(); XmlNode newChild = xmlDocument.ImportNode(xmlElement, true); xmlDocument.AppendChild(newChild); EncryptedXml encryptedXml = new EncryptedXml(xmlDocument); encryptedXml.AddKeyNameMapping("key", symmetricSecurityKey.GetSymmetricAlgorithm("http://www.w3.org/2001/04/xmlenc#tripledes-cbc")); encryptedXml.DecryptDocument(); return(xmlDocument.DocumentElement); }