Was looking around and found a few answers that suggests that I should use REST. But how would I integrate this in Qt/c++? Could anyone link some examples of this or maybe a few lines of code? Would really appreciate it!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It took me a lot of time to achieve it. The trickiest thing is that you have to decode your primary key. With the help of this question, I've decided to use OpenSSL and I've made the following code.
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("theStorageAccountKey");
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://myStorage.blob.core.windows.net/?comp=list"));
request.setRawHeader("Authorization","SharedKey myStorage:" + array);
request.setRawHeader("x-ms-date", date.toStdString().c_str());
request.setRawHeader("x-ms-version", version.toStdString().c_str());
QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(manageCloudReply()));
I hope it'll help somebody.
回答2:
Please check out this question. It covers what you ask and outlines couple of freely available C++ libraries, which you could incorporate to access Azure services.