Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Aadhaar Paperless Offline e-kyc

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.

For more information, see https://uidai.gov.in/ecosystem/authentication-devices-documents/about-aadhaar-paperless-offline-e-kyc.html

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

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
li_rc = loo_Zip.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_BdXml.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Dsig.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Cert.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Crypt.ConnectToNewObject("Chilkat_9_5_0.Crypt2")

loo_Crypt.HashAlgorithm = "sha256"
loo_Crypt.EncodingMode = "hexlower"

ls_StrToHash = "1234567890Lock@487"
loo_BdHash = create oleobject
li_rc = loo_BdHash.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Xml.ConnectToNewObject("Chilkat_9_5_0.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.