public partial class Form1 : Form{ const string uriTemplate = "https://{0}.table.core.windows.net/{1}"; const string uriTemplate2 = "https://{0}.table.core.windows.net/{1}/{2}"; string _sharedKey = "== your shared key from the portal goes here=="; string _accountName = "fastmotorcycle"; string _tableName = "fastbikes"; public Form1() { InitializeComponent(); } private void cmdMakeHeader_Click(object sender, EventArgs e) { var account = _accountName; var sharedKey = Convert.FromBase64String(_sharedKey); this.txtAccountName.Text = account; this.txtSharedKey.Text = _sharedKey; this.txtTableName.Text = _tableName; // Fill datetime field string datetime = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture); this.txtDate.Text = datetime; // Fill uri field string uri = string.Format(uriTemplate, _accountName, _tableName); this.txtURI.Text = uri; // Create request object WebRequest request = WebRequest.Create(uri); // Add date header request.ContentLength = 0; request.Headers.Add("x-ms-date", datetime); // Get resource var resource = request.RequestUri.PathAndQuery; // Sign date, account and uri string stringToSign = string.Format("{0}\n/{1}{2}", request.Headers["x-ms-date"], account, resource ); this.txtMessageToSign.Text = stringToSign; // Sign the string using shared key var hasher = new HMACSHA256(sharedKey); string signedSignature = Convert.ToBase64String(hasher.ComputeHash(Encoding.UTF8.GetBytes(stringToSign))); this.txtSignedMessage.Text = signedSignature; // Add authorization header string authorizationHeader = string.Format("{0} {1}:{2}", "SharedKeyLite", account, signedSignature); request.Headers.Add("Authorization", authorizationHeader); // Show the signed message this.txtSignedMessage.Text = request.Headers.Get(0).ToString() + "\r\n"; this.txtSignedMessage.Text += request.Headers.Get(1).ToString() + "\r\n"; // Show the entire header this.txtHttpHeader.Text = "x-ms-date:" + request.Headers.Get(0).ToString() + "\r\n"; this.txtHttpHeader.Text += "Authorization:" + request.Headers.Get(1).ToString() + "\r\n"; this.txtHttpHeader.Text += "Content-Type:" + "application/atom+xml" + "\r\n"; if (this.txtPartitionKey.Text == String.Empty || this.txtRowKey.Text == String.Empty) return; this.txtResponseBody.Text = string.Format(Strings.response_header, this.txtPartitionKey.Text, this.txtRowKey.Text); } private void cmdClip2_Click(object sender, EventArgs e) { Clipboard.SetData(DataFormats.Text, (Object)this.txtResponseBody.Text); } private void cmdClip1_Click(object sender, EventArgs e) { Clipboard.SetData(DataFormats.Text, (Object)this.txtHttpHeader.Text); }}
|