Question:
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?
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()); }