Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Aadhaar Paperless Offline e-kycOpens 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. For more information, see https://uidai.gov.in/ecosystem/authentication-devices-documents/about-aadhaar-paperless-offline-e-kyc.html
integer li_rc oleobject loo_Zip integer li_Success oleobject loo_Entry string ls_SharePhrase oleobject loo_BdXml oleobject loo_Dsig oleobject loo_Cert oleobject loo_PubKey integer li_BVerifyReferenceDigests integer li_BVerified oleobject loo_Crypt string ls_StrToHash oleobject loo_BdHash integer li_NumTimesToHash integer i string ls_TmpStr oleobject loo_Xml string ls_M_hash string ls_TmpStr string ls_E_hash // 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". loo_Zip = create oleobject // Use "Chilkat_9_5_0.Zip" for versions of Chilkat < 10.0.0 li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip") if li_rc < 0 then destroy loo_Zip MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_Zip.OpenZip("qa_data/xml_dsig/offline_paperless_kyc.zip") if li_Success = 0 then Write-Debug loo_Zip.LastErrorText destroy loo_Zip return end if // The .zip should contain 1 XML file. loo_Entry = loo_Zip.GetEntryByIndex(0) if loo_Zip.LastMethodSuccess = 0 then Write-Debug loo_Zip.LastErrorText destroy loo_Zip return end if // To get the contents, we need to specify the Share Phrase. ls_SharePhrase = "Lock@487" loo_Zip.DecryptPassword = ls_SharePhrase loo_BdXml = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdXml.ConnectToNewObject("Chilkat.BinData") // The XML file will be unzipped into the bdXml object. li_Success = loo_Entry.UnzipToBd(loo_BdXml) if li_Success = 0 then Write-Debug loo_Entry.LastErrorText destroy loo_Entry destroy loo_Zip destroy loo_BdXml return end if destroy loo_Entry // First verify the XML digital signature. loo_Dsig = create oleobject // Use "Chilkat_9_5_0.XmlDSig" for versions of Chilkat < 10.0.0 li_rc = loo_Dsig.ConnectToNewObject("Chilkat.XmlDSig") li_Success = loo_Dsig.LoadSignatureBd(loo_BdXml) if li_Success <> 1 then Write-Debug loo_Dsig.LastErrorText destroy loo_Zip destroy loo_BdXml destroy loo_Dsig return end if // 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. loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") li_Success = loo_Cert.LoadFromFile("qa_data/xml_dsig/uidai_auth_sign_prod_2023.cer") if li_Success <> 1 then Write-Debug loo_Cert.LastErrorText destroy loo_Zip destroy loo_BdXml destroy loo_Dsig destroy loo_Cert return end if // Get the certificate's public key. loo_PubKey = loo_Cert.ExportPublicKey() li_Success = loo_Dsig.SetPublicKey(loo_PubKey) destroy loo_PubKey // The XML in this example contains only 1 signature. li_BVerifyReferenceDigests = 1 li_BVerified = loo_Dsig.VerifySignature(li_BVerifyReferenceDigests) if li_BVerified = 0 then Write-Debug loo_Dsig.LastErrorText Write-Debug "The signature was not valid." destroy loo_Zip destroy loo_BdXml destroy loo_Dsig destroy loo_Cert return end if Write-Debug "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. loo_Crypt = create oleobject // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2") loo_Crypt.HashAlgorithm = "sha256" loo_Crypt.EncodingMode = "hexlower" ls_StrToHash = "1234567890Lock@487" loo_BdHash = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdHash.ConnectToNewObject("Chilkat.BinData") li_Success = loo_BdHash.AppendString(ls_StrToHash,"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" li_NumTimesToHash = 9 for i = 1 to li_NumTimesToHash ls_TmpStr = loo_Crypt.HashBdENC(loo_BdHash) loo_BdHash.Clear() loo_BdHash.AppendString(ls_TmpStr,"utf-8") next Write-Debug "Computed Mobile hash = " + loo_BdHash.GetString("utf-8") // Let's get the mobile hash stored in the XML and compare it with our computed hash. loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") li_Success = loo_Xml.LoadBd(loo_BdXml,1) ls_M_hash = loo_Xml.ChilkatPath("UidData|Poi|(m)") Write-Debug "Stored Mobile hash = " + ls_M_hash // Now do the same thing for the email hash: ls_StrToHash = "abc@gm.comLock@487" loo_BdHash.Clear() li_Success = loo_BdHash.AppendString(ls_StrToHash,"utf-8") for i = 1 to li_NumTimesToHash ls_TmpStr = loo_Crypt.HashBdENC(loo_BdHash) loo_BdHash.Clear() loo_BdHash.AppendString(ls_TmpStr,"utf-8") next Write-Debug "Computed Email hash = " + loo_BdHash.GetString("utf-8") ls_E_hash = loo_Xml.ChilkatPath("UidData|Poi|(e)") Write-Debug "Stored Email hash = " + ls_E_hash destroy loo_Zip destroy loo_BdXml destroy loo_Dsig destroy loo_Cert destroy loo_Crypt destroy loo_BdHash destroy loo_Xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.