Sample code for 30+ languages & platforms
Zig

Example: Http.SetOAuthRsaKey method

Demonstrates the SetOAuthRsaKey method.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const pfx = try chilkat.Pfx.init();
    defer pfx.deinit();
    pfx.loadPfxFile("qa_data/pfx/MCD_Sandbox_chilkat_iccp_API_Keys/chilkat_iccp-sandbox.p12", "keystorepassword") catch {
        std.debug.print("{s}\n", .{try pfx.getLastErrorText(alloc)});
        return;
    };

    const priv_key = try chilkat.PrivateKey.init();
    defer priv_key.deinit();
    pfx.privateKeyAt(0, priv_key) catch {
        std.debug.print("{s}\n", .{try pfx.getLastErrorText(alloc)});
        return;
    };

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Use OAuth1.0a authentication.
    http.setOAuth1(true);

    // Use your own consumer key (this is not a valid consumer key)
    http.setOAuthConsumerKey("123abc");

    http.setOAuthSigMethod("RSA-SHA256");

    http.setOAuthRsaKey(priv_key) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    // Tell Chilkat to automatically calculate and add the oauth_body_hash field when sending the request.
    http.setOAuthBodyHash(true);

    // Send this request to an endpoint at chilkatsoft.com.  The purpose of this example is to show
    // how the OAuth1.0a Authorization header is computed and sent by Chilkat.
    // The chilkatsoft.com site itself doesn't do OAuth1.  It's just ignoring the Authorization header.
    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpStr("POST", "https://chilkatsoft.com/echo_request_body.asp", "<notUsed>123</notUsed>", "utf-8", "application/xml", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    // Examine the request header we just sent..
    std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});

    // Sample output:

    // POST /echo_request_body.asp HTTP/1.1
    // Host: chilkatsoft.com
    // Accept: */*
    // Accept-Encoding: gzip
    // Content-Type: application/xml
    // Content-Length: 22
    // Authorization: OAuth oauth_consumer_key="123abc", oauth_nonce="A2E91C3B53E0BD7FBF71F441336679E358DDCEEE", oauth_body_hash="a5kPTsDwUwmBjC0voNlAAvM6YoaRS5X7sTO49jl3/h8=", oauth_timestamp="1756324932", oauth_signature_method="RSA-SHA256", oauth_version="1.0", oauth_signature="*****"
}