Zig Requires Chilkat v11.0.0+
Zig
IKOF Generation Code for Montenegro Fiscalization Service
See more _Miscellaneous_ Examples
Demonstrates computing the IKOF MD5 summary value as described in section 4.3 of this document: https://poreskauprava.gov.me/ResourceManager/FileDownload.aspx?rId=416042&rType=2Chilkat 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 concatenated_params = "12345678|2019-06-12T17:05:43+02:00|9952|bb123bb1231|cc123cc1231|ss123ss123|199.01";
// Get the private key from a pfx file.
const pfx = try chilkat.Pfx.init();
defer pfx.deinit();
pfx.loadPfxFile("qa_data/pfx/cert_test123.pfx", "test123") 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;
};
// Create IIC signature according to RSASSA-PKCS-v1_5 using SHA256
const rsa = try chilkat.Rsa.init();
defer rsa.deinit();
rsa.usePrivateKey(priv_key) catch {
std.debug.print("{s}\n", .{try rsa.getLastErrorText(alloc)});
return;
};
// PKCS-v1_5 is used by default.
rsa.setEncodingMode("hex");
rsa.setCharset("utf-8");
const hex_sig = try rsa.signStringENC(alloc, concatenated_params, "sha256");
std.debug.print("Signature value result is: {s}\n", .{hex_sig});
// Compute the MD5 hash of the bytes.
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
crypt.setEncodingMode("hex");
crypt.setHashAlgorithm("md5");
const bd = try chilkat.BinData.init();
defer bd.deinit();
bd.appendEncoded(hex_sig, "hex") catch {};
const md5_summary = try crypt.hashBdENC(alloc, bd);
std.debug.print("MD5 summary value is: {s}\n", .{md5_summary});
}