Zig Requires Chilkat v11.0.0+
Zig
Duplicate openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat
See more OpenSSL Examples
Demonstrates how to duplicate this OpenSSL command:openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.datThe in.dat file contains the original data that was signed, and can contain text or binary data of any type. The above OpenSSL command does the following:
- Creates a SHA256 digest of the contents of the input file.
- Verifies the SHA256 digest using the public key.
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.
const pub_key = try chilkat.PublicKey.init();
defer pub_key.deinit();
// Load the public key from an PEM file:
pub_key.loadFromFile("pubKey.pem") catch {
std.debug.print("{s}\n", .{try pub_key.getLastErrorText(alloc)});
return;
};
// Load the data of the original file that was signed.
const bd_file_data = try chilkat.BinData.init();
defer bd_file_data.deinit();
try bd_file_data.loadFile("in.dat");
// Load the signature.
const bd_sig = try chilkat.BinData.init();
defer bd_sig.deinit();
try bd_sig.loadFile("signature.sig");
const rsa = try chilkat.Rsa.init();
defer rsa.deinit();
// Import the public key into the RSA component:
rsa.usePublicKey(pub_key) catch {
std.debug.print("{s}\n", .{try rsa.getLastErrorText(alloc)});
return;
};
// OpenSSL uses big-endian.
rsa.setLittleEndian(false);
rsa.verifyBd(bd_file_data, "sha256", bd_sig) catch {
std.debug.print("{s}\n", .{try rsa.getLastErrorText(alloc)});
std.debug.print("The signature was invalid.\n", .{});
return;
};
std.debug.print("The signature was verified.\n", .{});
}