Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Unicode C Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Unicode C) Calculate a X_RISKIFIED_HMAC_SHA256 for riskified.com API Calls

Demonstrates how to calculate the value for the X_RISKIFIED_HMAC_SHA256 header for riskified.com HTTP requests (REST API calls).

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkJsonObjectW.h>
#include <C_CkCrypt2W.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkJsonObjectW json;
    const wchar_t *jsonBody;
    HCkCrypt2W crypt;
    const wchar_t *hmacHexStr;
    HCkStringBuilderW sbHmacHex;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Create the JSON that is to be the body of the HTTP request.
    // The JSON created by this code is shown at the bottom of this example.
    // 
    // The JSON Code Generator at http://tools.chilkat.io/ can be used
    // to generate the following code from sample JSON.

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateNull(json,L"order.cancel_reason");
    CkJsonObjectW_UpdateNull(json,L"order.cancelled_at");
    CkJsonObjectW_UpdateString(json,L"order.cart_token",L"68778783ad298f1c80c3bafcddeea02f");
    CkJsonObjectW_UpdateNull(json,L"order.closed_at");
    CkJsonObjectW_UpdateString(json,L"order.created_at",L"2008-01-10T11:00:00-05:00");
    CkJsonObjectW_UpdateString(json,L"order.currency",L"USD");
    CkJsonObjectW_UpdateString(json,L"order.email",L"bob.norman@hostmail.com");
    CkJsonObjectW_UpdateString(json,L"order.gateway",L"authorize_net");
    CkJsonObjectW_UpdateNumber(json,L"order.id",L"450789469");
    CkJsonObjectW_UpdateString(json,L"order.total_discounts",L"0.00");
    CkJsonObjectW_UpdateString(json,L"order.total_price",L"409.94");
    CkJsonObjectW_UpdateString(json,L"order.updated_at",L"2008-01-10T11:00:00-05:00");
    CkJsonObjectW_UpdateString(json,L"order.note",L"some note made by the shop’s stuff member");
    CkJsonObjectW_UpdateNull(json,L"order.browser_ip");
    CkJsonObjectW_UpdateString(json,L"order.discount_codes[0].amount",L"10.00");
    CkJsonObjectW_UpdateString(json,L"order.discount_codes[0].code",L"TENOFF");
    CkJsonObjectW_UpdateString(json,L"order.line_items[0].title",L"IPod Nano - 8gb - green");
    CkJsonObjectW_UpdateNumber(json,L"order.line_items[0].price",L"199.00");
    CkJsonObjectW_UpdateNumber(json,L"order.line_items[0].product_id",L"632910392");
    CkJsonObjectW_UpdateNumber(json,L"order.line_items[0].quantity",L"1");
    CkJsonObjectW_UpdateString(json,L"order.line_items[0].sku",L"IPOD2008GREEN");
    CkJsonObjectW_UpdateString(json,L"order.shipping_lines[0].code",L"Free Shipping");
    CkJsonObjectW_UpdateString(json,L"order.shipping_lines[0].price",L"0.00");
    CkJsonObjectW_UpdateString(json,L"order.shipping_lines[0].title",L"Free Shipping");
    CkJsonObjectW_UpdateNull(json,L"order.payment_details.avs_result_code");
    CkJsonObjectW_UpdateNull(json,L"order.payment_details.credit_card_bin");
    CkJsonObjectW_UpdateString(json,L"order.payment_details.credit_card_company",L"Visa");
    CkJsonObjectW_UpdateString(json,L"order.payment_details.credit_card_number",L"XXXX-XXXX-XXXX-4242");
    CkJsonObjectW_UpdateNull(json,L"order.payment_details.cvv_result_code");
    CkJsonObjectW_UpdateString(json,L"order.payment_details.authorization_id",L"RK346IK124");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.address1",L"Chestnut Street 92");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.address2",L"");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.city",L"Louisville");
    CkJsonObjectW_UpdateNull(json,L"order.billing_address.company");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.country",L"United States");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.country_code",L"US");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.first_name",L"Bob");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.last_name",L"Norman");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.name",L"Bob Norman");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.phone",L"555-625-1199");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.province",L"Kentucky");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.province_code",L"KY");
    CkJsonObjectW_UpdateString(json,L"order.billing_address.zip",L"40202");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.address1",L"Chestnut Street 92");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.address2",L"");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.city",L"Louisville");
    CkJsonObjectW_UpdateNull(json,L"order.shipping_address.company");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.country",L"United States");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.country_code",L"US");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.first_name",L"Bob");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.last_name",L"Norman");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.name",L"Bob Norman");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.phone",L"555-625-1199");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.province",L"Kentucky");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.province_code",L"KY");
    CkJsonObjectW_UpdateString(json,L"order.shipping_address.zip",L"40202");
    CkJsonObjectW_UpdateString(json,L"order.customer.created_at",L"2013-04-23T13:36:50-04:00");
    CkJsonObjectW_UpdateString(json,L"order.customer.email",L"bob.norman@hostmail.com");
    CkJsonObjectW_UpdateString(json,L"order.customer.first_name",L"Bob");
    CkJsonObjectW_UpdateNumber(json,L"order.customer.id",L"207119551");
    CkJsonObjectW_UpdateString(json,L"order.customer.last_name",L"Norman");
    CkJsonObjectW_UpdateNull(json,L"order.customer.note");
    CkJsonObjectW_UpdateNumber(json,L"order.customer.orders_count",L"0");
    CkJsonObjectW_UpdateBool(json,L"order.customer.verified_email",TRUE);

    // Emit the JSON in compact format..
    CkJsonObjectW_putEmitCompact(json,TRUE);
    // Get the JSON that will be HMAC'd and will also be the contents of the HTTP request body.
    jsonBody = CkJsonObjectW_emit(json);

    crypt = CkCrypt2W_Create();
    CkCrypt2W_putEncodingMode(crypt,L"hex");
    CkCrypt2W_putHashAlgorithm(crypt,L"sha256");
    CkCrypt2W_putMacAlgorithm(crypt,L"hmac");

    CkCrypt2W_SetMacKeyString(crypt,L"55fe0f4d4023bbdfbc124cabd88bf9bb");

    hmacHexStr = CkCrypt2W_macStringENC(crypt,jsonBody);
    if (CkCrypt2W_getLastMethodSuccess(crypt) != TRUE) {
        wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt));
        CkJsonObjectW_Dispose(json);
        CkCrypt2W_Dispose(crypt);
        return;
    }

    // We need a lowercase hmacHexStr...
    sbHmacHex = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbHmacHex,hmacHexStr);
    CkStringBuilderW_ToLowercase(sbHmacHex);

    hmacHexStr = CkStringBuilderW_getAsString(sbHmacHex);

    wprintf(L"The value of the X_RISKIFIED_HMAC_SHA256 should be: %s\n",hmacHexStr);

    // This example is only to show the HMAC SHA256 calculation.
    // See examples of sending REST requests to riskified.com at http://rest-examples.chilkat.io/riskified/default.cshtml

    // ----------------------------------------------
    // This is the JSON created by the above code..

    // {
    //   "order": {
    //     "cancel_reason": null,
    //     "cancelled_at": null,
    //     "cart_token": "68778783ad298f1c80c3bafcddeea02f",
    //     "closed_at": null,
    //     "created_at": "2008-01-10T11:00:00-05:00",
    //     "currency": "USD",
    //     "email": "bob.norman@hostmail.com",
    //     "gateway": "authorize_net",
    //     "id": 450789469,
    //     "total_discounts": "0.00",
    //     "total_price": "409.94",
    //     "updated_at": "2008-01-10T11:00:00-05:00",
    //     "note": "some note made by the shop’s stuff member",
    //     "browser_ip": null,
    //     "discount_codes": [
    //         {
    //             "amount": "10.00",
    //             "code": "TENOFF"
    //         }
    //     ],
    //     "line_items": [
    //         {
    //             "title": "IPod Nano - 8gb - green",
    //             "price": 199.00,
    //             "product_id": 632910392,
    //             "quantity": 1,
    //             "sku": "IPOD2008GREEN"
    //         }
    //     ],
    //     "shipping_lines": [
    //         {
    //             "code": "Free Shipping",
    //             "price": "0.00",
    //             "title": "Free Shipping"
    //         }
    //     ],
    //     "payment_details": {
    //         "avs_result_code": null,
    //         "credit_card_bin": null,
    //         "credit_card_company": "Visa",
    //         "credit_card_number": "XXXX-XXXX-XXXX-4242",
    //         "cvv_result_code": null,
    //         "authorization_id": "RK346IK124"
    //     },
    //     "billing_address": {
    //         "address1": "Chestnut Street 92",
    //         "address2": "",
    //         "city": "Louisville",
    //         "company": null,
    //         "country": "United States",
    //         "country_code": "US",
    //         "first_name": "Bob",
    //         "last_name": "Norman",
    //         "name": "Bob Norman",
    //         "phone": "555-625-1199",
    //         "province": "Kentucky",
    //         "province_code": "KY",
    //         "zip": "40202"
    //     },
    //     "shipping_address": {
    //         "address1": "Chestnut Street 92",
    //         "address2": "",
    //         "city": "Louisville",
    //         "company": null,
    //         "country": "United States",
    //         "country_code": "US",
    //         "first_name": "Bob",
    //         "last_name": "Norman",
    //         "name": "Bob Norman",
    //         "phone": "555-625-1199",
    //         "province": "Kentucky",
    //         "province_code": "KY",
    //         "zip": "40202"
    //     },
    //     "customer": {
    //         "created_at": "2013-04-23T13:36:50-04:00",
    //         "email": "bob.norman@hostmail.com",
    //         "first_name": "Bob",
    //         "id": 207119551,
    //         "last_name": "Norman",
    //         "note": null,
    //         "orders_count": 0,
    //         "verified_email": true
    //     }
    //  }
    // }


    CkJsonObjectW_Dispose(json);
    CkCrypt2W_Dispose(crypt);
    CkStringBuilderW_Dispose(sbHmacHex);

    }

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.