Rust Requires Chilkat v11.0.0+
Rust
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 Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let concatenated_params = "12345678|2019-06-12T17:05:43+02:00|9952|bb123bb1231|cc123cc1231|ss123ss123|199.01".to_string();
// Get the private key from a pfx file.
let pfx = chilkat::Pfx::new();
if pfx.load_pfx_file("qa_data/pfx/cert_test123.pfx", "test123").is_err() {
println!("{}", pfx.last_error_text());
return;
}
let priv_key = chilkat::PrivateKey::new();
if pfx.private_key_at(0, &priv_key).is_err() {
println!("{}", pfx.last_error_text());
return;
}
// Create IIC signature according to RSASSA-PKCS-v1_5 using SHA256
let rsa = chilkat::Rsa::new();
if rsa.use_private_key(&priv_key).is_err() {
println!("{}", rsa.last_error_text());
return;
}
// PKCS-v1_5 is used by default.
rsa.set_encoding_mode("hex");
rsa.set_charset("utf-8");
let hex_sig = rsa.sign_string_enc(&concatenated_params, "sha256").unwrap_or_default();
println!("Signature value result is: {}", hex_sig);
// Compute the MD5 hash of the bytes.
let crypt = chilkat::Crypt2::new();
crypt.set_encoding_mode("hex");
crypt.set_hash_algorithm("md5");
let bd = chilkat::BinData::new();
let _ = bd.append_encoded(&hex_sig, "hex");
let md5_summary = crypt.hash_bd_enc(&bd).unwrap_or_default();
println!("MD5 summary value is: {}", md5_summary);