Zig Requires Chilkat v11.0.0+
Zig
RSA Sign utf-8 Byte Representation of String
See more RSA Examples
Demontstrates how to sign the utf-8 byte representation of a string.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Load an RSA private key for signing.
const priv_key = try chilkat.PrivateKey.init();
defer priv_key.deinit();
priv_key.loadEncryptedPemFile("qa_data/pem/rsa_passwd.pem", "passwd") catch {
std.debug.print("{s}\n", .{try priv_key.getLastErrorText(alloc)});
return;
};
const rsa = try chilkat.Rsa.init();
defer rsa.deinit();
rsa.usePrivateKey(priv_key) catch {
std.debug.print("{s}\n", .{try rsa.getLastErrorText(alloc)});
return;
};
const original_data = "This is the string to be hashed an RSA signed.";
// Indicate that we want the utf-8 byte representation of the string to be signed
rsa.setCharset("utf-8");
// We want the RSA signature in base64 format
rsa.setEncodingMode("base64");
const sig_base64 = try rsa.signStringENC(alloc, original_data, "sha256");
std.debug.print("{s}\n", .{sig_base64});
}