login about faq

I’m close to getting a working example of using Chilkat libs to talk to Azure (Http/Crypt2 C++) my issue is it appears I’m not calculating the signature correctly, any chance I could get you to take a look at this and tell me where I might be going wrong?

//simple testing function
void local_was_sign_request(const char *request,CkString &str, wchar_t *name, wchar_t *primekey)
{
      CkCrypt2 enc;
      CkString strauth,strfinal,strid,strkey;
      strid.setStringU(name);
      strkey.setStringU(primekey);

enc.UnlockComponent("30-day trial");
      enc.put_HashAlgorithm("sha256");
      enc.SetHmacKeyString(strkey.getAnsi());
      enc.put_Charset("utf8");
      enc.put_EncodingMode("base64");
      enc.HmacStringENC(request,strauth);
      str.append("SharedKey ");
      str.append(strid.getAnsi());
      str.append(":");
      str.append(strauth.getUtf8());
}

According to MSFT the mechanism for signing is as follows:

Encoding the Signature

To encode the signature, call the HMAC-SHA256 algorithm on the UTF-8-encoded signature string and encode the result as Base64. Use the following format (shown as pseudocode):

Signature=Base64(HMAC-SHA256(UTF8(StringToSign)))

Based on what I’m doing I would think I’m doing exactly that?

asked Aug 03 '12 at 14:56

chilkat's gravatar image

chilkat ♦♦
11.8k316358421


what Microsoft leaves out is that they key they provide on their website is base64 encoded, so you have to use SetHmacKeyEncoded(key,"base64")

//simple testing function
void local_was_sign_request(const char request,CkString &str, wchar_t name, wchar_t *primekey)
{
      CkCrypt2 enc;
      CkString strauth,strfinal,strid,strkey;
      strid.setStringU(name);
      strkey.setStringU(primekey);

enc.UnlockComponent("30-day trial"); enc.put_HashAlgorithm("sha256"); enc.SetHmacKeyEncoded(strkey.getAnsi(),"base64"); enc.put_Charset("utf8"); enc.put_EncodingMode("base64"); enc.HmacStringENC(request,strauth); str.append("SharedKey "); str.append(strid.getAnsi()); str.append(":"); str.append(strauth.getUtf8()); }

link

answered Aug 03 '12 at 14:59

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×21
×4

Asked: Aug 03 '12 at 14:56

Seen: 1,763 times

Last updated: Aug 03 '12 at 14:59

powered by OSQA