Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL cConcatenatedParams
LOCAL oPfx
LOCAL oPrivKey
LOCAL oRsa
LOCAL cHexSig
LOCAL oCrypt
LOCAL oBd
LOCAL cMd5_summary
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
cConcatenatedParams := "12345678|2019-06-12T17:05:43+02:00|9952|bb123bb1231|cc123cc1231|ss123ss123|199.01"
// Get the private key from a pfx file.
oPfx := CreateObject("Chilkat.Pfx")
nSuccess := oPfx:LoadPfxFile("qa_data/pfx/cert_test123.pfx", "test123")
IF (nSuccess == 0)
? oPfx:LastErrorText
oPfx:destroy()
RETURN
ENDIF
oPrivKey := CreateObject("Chilkat.PrivateKey")
nSuccess := oPfx:PrivateKeyAt(0, oPrivKey)
IF (nSuccess == 0)
? oPfx:LastErrorText
oPfx:destroy()
oPrivKey:destroy()
RETURN
ENDIF
// Create IIC signature according to RSASSA-PKCS-v1_5 using SHA256
oRsa := CreateObject("Chilkat.Rsa")
nSuccess := oRsa:UsePrivateKey(oPrivKey)
IF (nSuccess == 0)
? oRsa:LastErrorText
oPfx:destroy()
oPrivKey:destroy()
oRsa:destroy()
RETURN
ENDIF
// PKCS-v1_5 is used by default.
oRsa:EncodingMode := "hex"
oRsa:Charset := "utf-8"
cHexSig := oRsa:SignStringENC(cConcatenatedParams, "sha256")
? "Signature value result is: " + cHexSig
// Compute the MD5 hash of the bytes.
oCrypt := CreateObject("Chilkat.Crypt2")
oCrypt:EncodingMode := "hex"
oCrypt:HashAlgorithm := "md5"
oBd := CreateObject("Chilkat.BinData")
oBd:AppendEncoded(cHexSig, "hex")
cMd5_summary := oCrypt:HashBdENC(oBd)
? "MD5 summary value is: " + cMd5_summary
oPfx:destroy()
oPrivKey:destroy()
oRsa:destroy()
oCrypt:destroy()
oBd:destroy()