Zig Requires Chilkat v11.0.0+
Zig
Duplicate openssl dgst -md5 -sign myKey.pem something.txt | openssl enc -base64 -A
See more RSA Examples
Demonstrates how to duplicate the creation of an RSA signature produced by this OpenSSL command:openssl dgst -md5 -sign myKey.pem something.txt | openssl enc -base64 -A
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 assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const pkey = try chilkat.PrivateKey.init();
defer pkey.deinit();
// Load the private key from an RSA PEM file:
try pkey.loadPemFile("myKey.pem");
const rsa = try chilkat.Rsa.init();
defer rsa.deinit();
// Import the private key into the RSA component:
rsa.usePrivateKey(pkey) catch {
std.debug.print("{s}\n", .{try rsa.getLastErrorText(alloc)});
return;
};
// OpenSSL uses BigEndian byte ordering:
rsa.setLittleEndian(false);
// The resulting signature will be a Base64 string:
rsa.setEncodingMode("base64");
// For simplicity, we're not loading
// the data to be signed from a file. We are instead simply
// using a literal string value.
const str_data = "This is the text to be signed.";
// Hash the input using MD5, and then sign the hash:
// Other valid hash algorithm choices are "md2" and "sha-1".
const base64_sig = try rsa.signStringENC(alloc, str_data, "md5");
std.debug.print("{s}\n", .{base64_sig});
std.debug.print("Success!\n", .{});
}