void dispatcherTimer_Tick(object sender, EventArgs e) { switch (status) { case 0: if (encryptedElements <= elementsToEncrypt.Length) { actElementToEncrypt = elementsToEncrypt[encryptedElements]; presentation.AddTextToInformationBox("Actual Element to encrypt is:" + actElementToEncrypt.Name); itemToEncrypt = this.animateElement(actElementToEncrypt.Name); dispatcherTimer.Interval = new TimeSpan(0, 0, 5); status = 1; } break; case 1: presentation.AddTextToInformationBox("Generate 256 AES Session Key to encrypt the element"); status = 2; break; case 2: presentation.AddTextToInformationBox("Session Key is: " + soap.LastSessionKey); status = 3; break; case 3: if (!soap.GetIsEncryptContent()) { string id = checkForID(itemToEncrypt); if (id != null) { presentation.AddTextToInformationBox("The " + actElementToEncrypt.Name + " has already an id: " + id); actId = id; } else { actId = soap.GetIdToElement(actElementToEncrypt.Name); presentation.AddTextToInformationBox("The " + actElementToEncrypt.Name + " gets the id: " + actId); createAttributeForElement(itemToEncrypt, "URI", "#" + actId); } } else { XmlNode encryptedElement = soap.SecuredSoap.GetElementsByTagName(actElementToEncrypt.Name)[0]; foreach (XmlAttribute att in encryptedElement.FirstChild.Attributes) { if (att.Name.Equals("Id")) { actId = att.Value; } } presentation.AddTextToInformationBox("The Id for the EncryptedData Element will be: " + actId); } status = 4; break; case 4: presentation.AddTextToInformationBox("Calculate cipher value of the element"); status = 5; break; case 5: XmlNodeList encryptedDataElements = soap.SecuredSoap.GetElementsByTagName("xenc:EncryptedData"); foreach (XmlNode node in encryptedDataElements) { foreach (XmlAttribute att in node.Attributes) { if (att.Name.Equals("Id") && att.Value.Equals(actId)) { actEncryptedDataElement = node; foreach (XmlNode child in node.ChildNodes) { if (child.Name.Equals("xenc:CipherData")) { cipherValueOfElement = child.FirstChild.InnerText; } } } } } presentation.AddTextToInformationBox("CipherValue is:" + cipherValueOfElement); status = 6; break; case 6: presentation.AddTextToInformationBox("Create EncryptedData Element"); rootItem = (TreeViewItem)presentation.treeView.Items[0]; presentation.treeView.Items.Clear(); header = new TreeViewItem(); StackPanel panel = new StackPanel(); TextBlock block = new TextBlock(); block.FontSize = 16; block.Text = "Encrypted Data Element"; panel.Children.Add(block); header.Header = panel; presentation.treeView.Items.Add(header); actEncDataItem = addChildElement(header, actEncryptedDataElement, true); status = 7; break; case 7: presentation.AddTextToInformationBox("Create the EncryptionMethod Element "); addChildElement(actEncDataItem, actEncryptedDataElement.FirstChild, false); status = 8; break; case 8: presentation.AddTextToInformationBox("Create the CipherData Element "); foreach (XmlNode node in actEncryptedDataElement.ChildNodes) { if (node.Name.Equals("xenc:CipherData")) { actcipherdata = node; } } actcipherdataitem = addChildElement(actEncDataItem, actcipherdata, false); status = 9; break; case 9: presentation.AddTextToInformationBox("Create the CipherValue Element"); actciphervalueitem = addChildElement(actcipherdataitem, actcipherdata.FirstChild, false); status = 10; break; case 10: presentation.AddTextToInformationBox("Insert the cipher value"); createValue(actciphervalueitem, actcipherdata.FirstChild.InnerText); status = 11; break; case 11: presentation.treeView.Items.Clear(); presentation.treeView.Items.Add(rootItem); status = 12; break; case 12: if (soap.GetIsEncryptContent()) { presentation.AddTextToInformationBox("Replase the content of the " + actElementToEncrypt.Name); presentation.AddTextToInformationBox("Element with the created EncryptedData Element"); itemToEncrypt.Items.Clear(); TreeViewItem parent1 = (TreeViewItem)actEncDataItem.Parent; parent1.Items.Remove(actEncDataItem); itemToEncrypt.Items.Add(actEncDataItem); } else { TreeViewItem parent = (TreeViewItem)itemToEncrypt.Parent; index = parent.Items.IndexOf(itemToEncrypt); TreeViewItem parent1 = (TreeViewItem)actEncDataItem.Parent; parent1.Items.Remove(actEncDataItem); parent.Items.RemoveAt(index); parent.Items.RemoveAt(index); presentation.AddTextToInformationBox("Replase the the " + actElementToEncrypt.Name + " Element"); parent.Items.Insert(index, actEncDataItem); TextBlock tb = new TextBlock(); TextBlock tb1 = new TextBlock(); TextBlock tb2 = new TextBlock(); tb.Name = "tbNameClose"; tb.Text = "/xenc:EncryptedData"; tb1.Text = "<"; tb2.Text = ">"; StackPanel panel1 = new StackPanel(); panel1.Orientation = System.Windows.Controls.Orientation.Horizontal; panel1.Children.Add(tb1); panel1.Children.Add(tb); panel1.Children.Add(tb2); tb.Foreground = elemBrush; tb1.Foreground = elemBrush; tb2.Foreground = elemBrush; TreeViewItem closeItem = new TreeViewItem(); closeItem.Header = panel1; parent.Items.Insert(index + 1, closeItem); } status = 13; break; case 13: presentation.AddTextToInformationBox("Check for Header"); if (!soap.HadHeader) { this.secHeader = false; status = 14; } else { this.secHeader = true; status = 15; } break; case 14: presentation.AddTextToInformationBox("No Header found. Create SOAP and Security Header"); addChildElement("s:Envelope", soap.SecuredSoap.GetElementsByTagName("s:Header")[0], true); addChildElement("s:Header", soap.SecuredSoap.GetElementsByTagName("wsse:Security")[0], true); status = 15; break; case 15: presentation.AddTextToInformationBox("Create Encrypted Key"); actEncKey = addChildElement("wsse:Security", soap.SecuredSoap.GetElementsByTagName("xenc:EncryptedKey")[0], true); status = 16; break; case 16: presentation.AddTextToInformationBox("Create Encryption Method Element"); addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("xenc:EncryptionMethod")[0], true); status = 17; break; case 17: presentation.AddTextToInformationBox("Add Key Info Element"); TreeViewItem keyInfo = addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("ds:KeyInfo")[0], true); keyInfo.IsExpanded = true; presentation.CopyXmlToTreeView(soap.SecuredSoap.GetElementsByTagName("ds:KeyInfo")[0].FirstChild, keyInfo); status = 18; break; case 18: presentation.AddTextToInformationBox("Create CipherData Element"); actcipherdataitem = addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("xenc:CipherData")[0], false); status = 19; break; case 19: presentation.AddTextToInformationBox("Create CipherValue Element"); actciphervalueitem = addChildElement(actcipherdataitem, soap.SecuredSoap.GetElementsByTagName("xenc:CipherValue")[0], false); status = 20; break; case 20: presentation.AddTextToInformationBox("Create CipherValue Element by encrypting the session key with the public key of the web service"); status = 21; break; case 21: presentation.AddTextToInformationBox("Cipher Value is: " + soap.SecuredSoap.GetElementsByTagName("xenc:CipherValue")[0].InnerText); status = 22; break; case 22: presentation.AddTextToInformationBox("Insert Cipher Value"); createValue(actciphervalueitem, soap.SecuredSoap.GetElementsByTagName("xenc:CipherValue")[0].InnerText); status = 23; break; case 23: presentation.AddTextToInformationBox("Create Reference List"); actRefList = addChildElement(actEncKey, soap.SecuredSoap.GetElementsByTagName("xenc:ReferenceList")[0], false); status = 24; break; case 24: status = 25; presentation.AddTextToInformationBox("Insert Data Reference"); addChildElement(actRefList, soap.SecuredSoap.GetElementsByTagName("xenc:ReferenceList")[0], false); status = 25; break; case 25: dispatcherTimer.Stop(); presentation._namespacesTable.Clear(); presentation.animationRunning = false; status = 0; soap.ShowSecuredSoap(); break; } }