Xbase++ Requires Chilkat v11.0.0+
Xbase++
Aadhaar Paperless Offline e-kyc
See more XML Digital Signatures Examples
Opens an encrypted .zip containing Aadhaar Paperless Offline e-KYC XML. Gets the XML and validates the digital signature. Then computes the hash for the mobile number and Email ID.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oZip
LOCAL oEntry
LOCAL cSharePhrase
LOCAL oBdXml
LOCAL oDsig
LOCAL oCert
LOCAL oPubKey
LOCAL nBVerifyReferenceDigests
LOCAL nBVerified
LOCAL oCrypt
LOCAL cStrToHash
LOCAL oBdHash
LOCAL nNumTimesToHash
LOCAL i
LOCAL cTmpStr
LOCAL oXml
LOCAL cM_hash
LOCAL cTmpStr
LOCAL cE_hash
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Open the .zip containing the Aadhaar Paperless Offline e-KYC XML.
// The .zip is encrypted using the "Share Phrase".
oZip := CreateObject("Chilkat.Zip")
nSuccess := oZip:OpenZip("qa_data/xml_dsig/offline_paperless_kyc.zip")
IF (nSuccess == 0)
? oZip:LastErrorText
oZip:destroy()
RETURN
ENDIF
// The .zip should contain 1 XML file.
oEntry := CreateObject("Chilkat.ZipEntry")
nSuccess := oZip:EntryAt(0, oEntry)
IF (nSuccess == 0)
? oZip:LastErrorText
oZip:destroy()
oEntry:destroy()
RETURN
ENDIF
// To get the contents, we need to specify the Share Phrase.
cSharePhrase := "Lock@487"
oZip:DecryptPassword := cSharePhrase
oBdXml := CreateObject("Chilkat.BinData")
// The XML file will be unzipped into the bdXml object.
nSuccess := oEntry:UnzipToBd(oBdXml)
IF (nSuccess == 0)
? oEntry:LastErrorText
oZip:destroy()
oEntry:destroy()
oBdXml:destroy()
RETURN
ENDIF
// First verify the XML digital signature.
oDsig := CreateObject("Chilkat.XmlDSig")
nSuccess := oDsig:LoadSignatureBd(oBdXml)
IF (nSuccess == 0)
? oDsig:LastErrorText
oZip:destroy()
oEntry:destroy()
oBdXml:destroy()
oDsig:destroy()
RETURN
ENDIF
// The UIDAI XML signature does not contain the KeyInfo, so we must load the uidai certificate
// and indicate that its public key is to be used for verifying the signature.
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadFromFile("qa_data/xml_dsig/uidai_auth_sign_prod_2023.cer")
IF (nSuccess == 0)
? oCert:LastErrorText
oZip:destroy()
oEntry:destroy()
oBdXml:destroy()
oDsig:destroy()
oCert:destroy()
RETURN
ENDIF
// Get the certificate's public key.
oPubKey := CreateObject("Chilkat.PublicKey")
oCert:GetPublicKey(oPubKey)
oDsig:SetPublicKey(oPubKey)
// The XML in this example contains only 1 signature.
nBVerifyReferenceDigests := 1
nBVerified := oDsig:VerifySignature(nBVerifyReferenceDigests)
IF (nBVerified == 0)
? oDsig:LastErrorText
? "The signature was not valid."
oZip:destroy()
oEntry:destroy()
oBdXml:destroy()
oDsig:destroy()
oCert:destroy()
oPubKey:destroy()
RETURN
ENDIF
? "The XML digital signature is valid."
// Let's compute the hash for the Mobile Number.
// Hashing logic for Mobile Number :
// Sha256(Sha256(Mobile+SharePhrase))*number of times last digit of Aadhaar number
// (Ref ID field contains last 4 digits).
//
// Example :
// Mobile: 1234567890
// Aadhaar Number:XXXX XXXX 3632
// Passcode : Lock@487
// Hash: Sha256(Sha256(1234567890Lock@487))*2
// In case of Aadhaar number ends with Zero we will hashed one time.
oCrypt := CreateObject("Chilkat.Crypt2")
oCrypt:HashAlgorithm := "sha256"
oCrypt:EncodingMode := "hexlower"
cStrToHash := "1234567890Lock@487"
oBdHash := CreateObject("Chilkat.BinData")
nSuccess := oBdHash:AppendString(cStrToHash, "utf-8")
// Hash a number of times equal to the last digit of your Aadhaar number.
// If the Aadhaar number ends with 0, then hash one time.
// For this example, we'll just set the number of times to hash
// for the case where an Aadhaar number ends in "9"
nNumTimesToHash := 9
FOR i := 1 TO nNumTimesToHash
cTmpStr := oCrypt:HashBdENC(oBdHash)
oBdHash:Clear()
oBdHash:AppendString(cTmpStr, "utf-8")
NEXT
? "Computed Mobile hash = " + oBdHash:GetString("utf-8")
// Let's get the mobile hash stored in the XML and compare it with our computed hash.
oXml := CreateObject("Chilkat.Xml")
nSuccess := oXml:LoadBd(oBdXml, 1)
cM_hash := oXml:ChilkatPath("UidData|Poi|(m)")
? "Stored Mobile hash = " + cM_hash
// Now do the same thing for the email hash:
cStrToHash := "abc@gm.comLock@487"
oBdHash:Clear()
nSuccess := oBdHash:AppendString(cStrToHash, "utf-8")
FOR i := 1 TO nNumTimesToHash
cTmpStr := oCrypt:HashBdENC(oBdHash)
oBdHash:Clear()
oBdHash:AppendString(cTmpStr, "utf-8")
NEXT
? "Computed Email hash = " + oBdHash:GetString("utf-8")
cE_hash := oXml:ChilkatPath("UidData|Poi|(e)")
? "Stored Email hash = " + cE_hash
oZip:destroy()
oEntry:destroy()
oBdXml:destroy()
oDsig:destroy()
oCert:destroy()
oPubKey:destroy()
oCrypt:destroy()
oBdHash:destroy()
oXml:destroy()