private void txtProcessDemo_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; StringBuilder sbResultsForStorage = new StringBuilder(); AzureQueueStorage aqs = new AzureQueueStorage(txtAccount.Text, string.Format("http://{0}.queue.core.windows.net", txtAccount.Text), txtSharedKey.Text, "SharedKey"); azureResults ar = aqs.Messages(cmdType.get, bulkTag, "", "visibilitytimeout=7200", ""); string MessageID = ""; string PopReceipt = ""; string Message = ""; if (ar.Body != null) { System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); if (ar.Succeeded) { xdoc.LoadXml(ar.Body); System.Xml.XmlNodeList nodes = xdoc.SelectNodes("//QueueMessage"); StringBuilder sbMultipart = new StringBuilder(); if (nodes.Count == 0) txtMessage.Text = "No message to process"; else foreach (System.Xml.XmlNode node in nodes) { MessageID = node.SelectSingleNode("MessageId").InnerText; PopReceipt = node.SelectSingleNode("PopReceipt").InnerText; Message = node.SelectSingleNode("MessageText").InnerText; System.Xml.XmlDocument msgDoc = new XmlDocument(); msgDoc.LoadXml(Message); string newAccount = msgDoc.SelectSingleNode("//account[1]").InnerXml; string newKey = msgDoc.SelectSingleNode("//key[1]").InnerXml; string newSource = msgDoc.SelectSingleNode("//source[1]").InnerXml; string updateID = msgDoc.SelectSingleNode("//updateID[1]").InnerXml; string newTable = msgDoc.SelectSingleNode("//table[1]").InnerXml; AzureTableStorage ats = new AzureTableStorage(txtAccount.Text, "", txtSharedKey.Text, "SharedKey"); AzureTableStorage ats1 = new AzureTableStorage(txtAccount.Text, "", txtSharedKey.Text, "SharedKey"); azureHelper ah = new azureHelper(txtAccount.Text, txtEndpoint.Text, txtSharedKey.Text, "SharedKey"); string mrgMessage = string.Format(queueUpdateCreationEntity, updateID, 0, 0); ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, ""); ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", string.Format("<m:properties>\n\t<d:PartitionKey>{0}</d:PartitionKey>\n\t<d:RowKey>000000000000000</d:RowKey><d:StartedProcessing>{1}</d:StartedProcessing></m:properties>", updateID, DateTime.UtcNow.ToLongTimeString()), ""); AzureBlobStorage abs = new AzureBlobStorage(newAccount, string.Format("http://{0}.blob.core.windows.net", newAccount), newKey, "SharedKey"); AzureTableStorage atsNew = new AzureTableStorage(newAccount, string.Format("http://{0}.blob.core.windows.net", newAccount), newKey, "SharedKey"); ar = atsNew.Tables(cmdType.post, newTable); if (ar.Succeeded || ar.StatusCode == System.Net.HttpStatusCode.Conflict) { ar = new azureResults(); string newContainer = newSource.Replace(string.Format("http://{0}.blob.core.windows.net/", newAccount), ""); newContainer = newContainer.Substring(0, newContainer.IndexOf("/")); string newBlob = newSource.Replace(string.Format("http://{0}.blob.core.windows.net/", newAccount), "").Replace(newContainer, ""); byte[] blob = abs.GetBlob(newContainer, newBlob, "", ref ar); string x = new System.Text.UTF8Encoding().GetString(blob); x = x.Substring(x.IndexOf("<")); msgDoc.LoadXml(x); int errorCt = 0; int processedCt = 0; //Instantiate an XmlNamespaceManager object. System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(xdoc.NameTable); //Add the namespaces used in books.xml to the XmlNamespaceManager. xmlnsManager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices"); xmlnsManager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); XmlNodeList pnodes = msgDoc.SelectNodes("//m:properties", xmlnsManager); int iCounter = 101; int iResponse = 1; foreach (XmlNode pnode in pnodes) { if (iCounter > 100) { if (sbMultipart.Length > 0) { sbMultipart.Append("</entry>"); ProcessMultiPartForStatus(ats.auth, ah.entityGroupTransaction(cmdType.post, newTable, sbMultipart.ToString()), bulkTag, updateID, iResponse.ToString("D15"), ref processedCt, ref errorCt, "201 Created"); ar = ats1.Entities(cmdType.post, bulkTag, updateID, iResponse.ToString("D15"), sbResultsForStorage.ToString(), ""); mrgMessage = string.Format(queueUpdateCreationEntity, updateID, processedCt, errorCt); ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, "", "*"); iResponse++; } sbMultipart = new StringBuilder(); sbMultipart.AppendFormat(@"<?xml version=""1.0"" encoding=""utf-8"" ?><entry xml:base=""http://finseldemos.table.core.windows.net/"" xmlns:d=""http://schemas.microsoft.com/ado/2007/08/dataservices"" xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" xmlns=""http://www.w3.org/2005/Atom"">"); iCounter = 0; } sbMultipart.Append(pnode.OuterXml); iCounter++; } sbMultipart.Append("</entry>"); ProcessMultiPartForStatus(ats.auth, ah.entityGroupTransaction(cmdType.post, newTable, sbMultipart.ToString()), bulkTag, updateID, iResponse.ToString("D15"), ref processedCt, ref errorCt, "201 Created"); mrgMessage = string.Format(queueUpdateCreationEntity, updateID, processedCt, errorCt).Replace("Processing", "Completed"); ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, "", "*"); } else { mrgMessage = string.Format(queueUpdateCreationEntity, updateID, 0, 0).Replace("Processing", "Failed to create table!"); ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", mrgMessage, ""); } aqs.Messages(cmdType.delete, bulkTag, "", string.Format("popreceipt={0}", PopReceipt), MessageID); ats.Entities(cmdType.merge, bulkTag, updateID, "000000000000000", string.Format("<m:properties>\n\t<d:PartitionKey>{0}</d:PartitionKey>\n\t<d:RowKey>000000000000000</d:RowKey><d:CompletedProcessing>{1}</d:CompletedProcessing></m:properties>", updateID, DateTime.UtcNow.ToLongTimeString()), ""); } } else txtMessage.Text = "No message to process"; ProcessResults(ar); this.Cursor = Cursors.Default; } }
/// <summary> /// Decrypt string data with a supported cipher, authenticate the cipher using a supported digest type, deviate the cipher password with a supported divination type, and, finally pad a cipher using a supported padding type. /// </summary> /// <param name="data">String data.</param> /// <param name="password">Cipher password. Will be deviated using the supplied divination type.</param> /// <param name="salt">Cipher salt to be used, should be proper format for the cipher type. (Note: Normally 8, or, 14 bytes)</param> /// <param name="secondaryVerifier">Secondary data you wish to use to validate the cipher. This is a secondary validation check. The cipher binary is already validated. (Note: This will increase the size of the cipher)</param> /// <returns>Byte data</returns> public static string FromEncryptionAtRest(this string data, string password, byte[] salt, string secondaryVerifier = null) { var iv = new UTF8Encoding().GetBytes(data.Substring(0, 16)); var key = password.ToHash(salt); var suspectedInputVerifier = data.Substring(data.Length - 32, data.Length); var input = new UTF8Encoding().GetBytes(data.Substring(16, data.Length - 32)); var expectedInputVerifier = input.ToHmac(key.Data, salt); if (!suspectedInputVerifier.Equals(expectedInputVerifier.Data)) { return string.Empty; } var cipher = CipherUtilities.GetCipher("AES/CBC/PKCS7"); cipher.Init(false, new ParametersWithIV(new KeyParameter(key.Data), iv)); var outputData = cipher.DoFinal(input); cipher.Reset(); var output = new UTF8Encoding().GetString(outputData); if (!string.IsNullOrEmpty(secondaryVerifier)) { var expectedVerifier = secondaryVerifier.ToHmac(key.Data, salt).Data.ToHex(); var suspectedVerifier = output.Substring(output.Length - 64, 64); if (!expectedVerifier.SequenceEqual(suspectedVerifier)) { return string.Empty; } output = output.Substring(0, output.Length - 64); } return output; }
protected override bool SerializeToXmlElement(XmlWriter writer, String elementName) { bool writeMe = base.SerializeToXmlElement(writer, elementName); bool writeComment = this.OptionalIssuedTokenParameters.Count > 0; if (writeComment && writer != null) { MemoryStream memoryStream = new MemoryStream(); using (XmlTextWriter commentWriter = new XmlTextWriter(memoryStream, Encoding.UTF8)) { commentWriter.Formatting = Formatting.Indented; commentWriter.WriteStartElement(ConfigurationStrings.AlternativeIssuedTokenParameters); foreach (IssuedTokenParametersElement element in this.OptionalIssuedTokenParameters) { element.SerializeToXmlElement(commentWriter, ConfigurationStrings.IssuedTokenParameters); } commentWriter.WriteEndElement(); commentWriter.Flush(); string commentString = new UTF8Encoding().GetString(memoryStream.GetBuffer(), 0, (int)memoryStream.Length); writer.WriteComment(commentString.Substring(1, commentString.Length - 1)); commentWriter.Close(); } } return writeMe || writeComment; }
protected override bool SerializeToXmlElement(XmlWriter writer, string elementName) { bool flag = base.SerializeToXmlElement(writer, elementName); bool flag2 = this.OptionalIssuedTokenParameters.Count > 0; if (flag2 && (writer != null)) { MemoryStream w = new MemoryStream(); using (XmlTextWriter writer2 = new XmlTextWriter(w, Encoding.UTF8)) { writer2.Formatting = Formatting.Indented; writer2.WriteStartElement("alternativeIssuedTokenParameters"); foreach (IssuedTokenParametersElement element in this.OptionalIssuedTokenParameters) { element.SerializeToXmlElement(writer2, "issuedTokenParameters"); } writer2.WriteEndElement(); writer2.Flush(); string str = new UTF8Encoding().GetString(w.GetBuffer(), 0, (int) w.Length); writer.WriteComment(str.Substring(1, str.Length - 1)); writer2.Close(); } } if (!flag) { return flag2; } return true; }