Can anyone help me to access azure storage using Qt/c++ ?
Here's my code.
QString date = "Tue, 18 Mar 2014 21:49:13 GMT";
QString datastring = "GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:"+date+"\nx-ms-version:2009-09-19\n/mystorage/\ncomp:list";
QByteArray ba = datastring.toUtf8();
unsigned char* signature = reinterpret_cast<unsigned char*>(ba.data());
QByteArray kba = QByteArray::fromBase64("<accountkey>");
unsigned char* key = (unsigned char*) kba.data();
unsigned char result[EVP_MAX_MD_SIZE];
unsigned int result_len;
ENGINE_load_builtin_engines();
ENGINE_register_all_complete();
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key, strlen((const char*)key), EVP_sha256(), NULL);
HMAC_Update(&ctx, signature, strlen((const char*)signature));
HMAC_Final(&ctx, result, &result_len);
HMAC_CTX_cleanup(&ctx);
QByteArray array = QByteArray::fromRawData((char*)result, result_len);
array = array.toBase64();
qDebug() << "signature hash" << array;
QString version = "2009-09-19";
//requesting the list of container to Windows Azure
QNetworkAccessManager* manager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl("http://myaccount.blob.core.windows.net/?comp=list"));
request.setRawHeader("Authorization","SharedKey myaccount:"+array);
request.setRawHeader("x-ms-date", date.toStdString().c_str());
request.setRawHeader("x-ms-version", version.toStdString().c_str());
manager->get(request);
The request returns the following error
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:6f7a9bf3-81f2-4191-84b8-c1cd1747411f
Time:2014-03-18T05:03:12.2134625Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'T4vqb/a9SkDnWLvHXyhIEBREHWpBMfhuuMFQwxtRXMs=' is not the same as any computed signature. Server used following string to sign: 'GET
x-ms-date:Tue, 18 Mar 2014 21:49:13 GMT
x-ms-version:2009-09-19
/mystorage/
comp:list'.</AuthenticationErrorDetail></Error>"
I don't know the exact error in the code. How can i fix this.
I got the source from here