Sample code for 30+ languages & platforms
Zig

Example: Crypt2.HashStringENC method

Demonstrates how to call the HashStringENC 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 crypt = try chilkat.Crypt2.init();
    defer crypt.deinit();

    const s = "får";

    // The string "får" in utf-8 is composed of these bytes: 0x66 0xC3 0xA5 0x72
    crypt.setCharset("utf-8");

    crypt.setEncodingMode("hex_lower");
    crypt.setHashAlgorithm("sha256");

    // Get the hex string for the sha-256 hash of the utf-8 byte representation of the string
    const hash_str = try crypt.hashStringENC(alloc, s);

    std.debug.print("{s}\n", .{hash_str});

    // Output:
    // cb8f773dd592337ed7f928012a60f48e1efb357beeda124a54461410e216fece
}