Sample code for 30+ languages & platforms
PowerBuilder

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=2

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
string ls_ConcatenatedParams
oleobject loo_Pfx
oleobject loo_PrivKey
oleobject loo_Rsa
string ls_HexSig
oleobject loo_Crypt
oleobject loo_Bd
string ls_Md5_summary

li_Success = 0

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

ls_ConcatenatedParams = "12345678|2019-06-12T17:05:43+02:00|9952|bb123bb1231|cc123cc1231|ss123ss123|199.01"

// Get the private key from a pfx file.
loo_Pfx = create oleobject
li_rc = loo_Pfx.ConnectToNewObject("Chilkat.Pfx")
if li_rc < 0 then
    destroy loo_Pfx
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Pfx.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
if li_Success = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    return
end if

loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")

li_Success = loo_Pfx.PrivateKeyAt(0,loo_PrivKey)
if li_Success = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    destroy loo_PrivKey
    return
end if

// Create IIC signature according to RSASSA-PKCS-v1_5 using SHA256
loo_Rsa = create oleobject
li_rc = loo_Rsa.ConnectToNewObject("Chilkat.Rsa")

li_Success = loo_Rsa.UsePrivateKey(loo_PrivKey)
if li_Success = 0 then
    Write-Debug loo_Rsa.LastErrorText
    destroy loo_Pfx
    destroy loo_PrivKey
    destroy loo_Rsa
    return
end if

// PKCS-v1_5 is used by default.
loo_Rsa.EncodingMode = "hex"
loo_Rsa.Charset = "utf-8"
ls_HexSig = loo_Rsa.SignStringENC(ls_ConcatenatedParams,"sha256")

Write-Debug "Signature value result is: " + ls_HexSig

// Compute the MD5 hash of the bytes.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")

loo_Crypt.EncodingMode = "hex"
loo_Crypt.HashAlgorithm = "md5"
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

loo_Bd.AppendEncoded(ls_HexSig,"hex")
ls_Md5_summary = loo_Crypt.HashBdENC(loo_Bd)

Write-Debug "MD5 summary value is: " + ls_Md5_summary


destroy loo_Pfx
destroy loo_PrivKey
destroy loo_Rsa
destroy loo_Crypt
destroy loo_Bd