Unicode C++
Unicode C++
ChartURL - Create a Signed URL
See more HTTP Misc Examples
Demonstrates how to create a signed URL for ChartURL.Chilkat Unicode C++ Downloads
#include <CkCrypt2W.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkCrypt2W crypt;
// Example key: "dek-d7a46236eda961a6c3c18ffcc6b077ba87d27e9ae85f7842c6d427c265dd5f69d5131308d93332353d4a55a4b1160fcf516515a4a9f0aa50fbf2d7a2e7d0f1c5"
const wchar_t *key = L"charturl-sign-encrypt-key";
// Example token: "dt-RwYN"
const wchar_t *token = L"charturl-token";
const wchar_t *slug = L"weekly-activity";
const wchar_t *data = L"{ \"options\": {\"data\": {\"columns\": [[\"This Week\",10,13],[\"Last Week\",9,5]]}}}";
crypt.put_HashAlgorithm(L"SHA256");
crypt.put_MacAlgorithm(L"HMAC");
crypt.SetMacKeyString(key);
crypt.put_EncodingMode(L"base64");
CkJsonObjectW json;
json.Load(data);
wprintf(L"json = %s\n",json.emit());
const wchar_t *sig = crypt.macStringENC(json.emit());
CkStringBuilderW sbUrl;
sbUrl.Append(L"https://charturl.com/i/");
sbUrl.Append(token);
sbUrl.Append(L"/");
sbUrl.Append(slug);
sbUrl.Append(L"?d=");
sbUrl.Append(crypt.encodeString(json.emit(),L"utf-8",L"url"));
sbUrl.Append(L"&s=");
sbUrl.Append(crypt.encodeString(sig,L"utf-8",L"url"));
wprintf(L"Signed URL: %s\n",sbUrl.getAsString());
}