PHP code example of itxshakil / aadhaar-offline

1. Go to this page and download the library: Download itxshakil/aadhaar-offline library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

itxshakil / aadhaar-offline example snippets


use Shakil\AadhaarOffline\OfflineKycReader;

$reader = OfflineKycReader::create(certificates: ['/path/to/uidai_offline_publickey_2026.cer']);

$kyc = $reader->verifyZip($_FILES['aadhaar_zip']['tmp_name'], $_POST['share_code']);

$kyc->name();                    // "Asha Verma"
$kyc->dob()?->format('Y-m-d');   // "1990-08-15"
$kyc->gender()?->label();        // "Female"
$kyc->address()->pincode;        // "110024"
$kyc->maskedAadhaar();           // "XXXX XXXX 5678"
$kyc->matchesMobile($_POST['phone']); // true / false

// The ZIP the resident downloaded from UIDAI, plus their 4-digit share code
$kyc = $reader->fromZip($path, '1234')->verify();

// Signed XML returned by a KYC vendor's OTP flow. Still verified locally.
$kyc = $reader->fromXml($vendorResponse['raw_xml'], shareCode: '1234')->verify();

// An XML file on disk
$kyc = $reader->fromXmlFile('/path/to/offline.xml', '1234')->verify();

// The Secure QR code: pass the scanned text, a long string of digits
$kyc = $reader->fromSecureQr($scannedDigits)->verify();

// One-step shortcuts
$kyc = $reader->verifyZip($path, '1234');
$kyc = $reader->verifyXml($xml, '1234');
$kyc = $reader->verifySecureQr($scannedDigits);

use Shakil\AadhaarOffline\Exceptions\{InvalidSignatureException, StaleKycException};

try {
    $kyc = $reader->verifyZip($path, $shareCode);
} catch (InvalidSignatureException) {
    // Forged, edited, or signed by an untrusted key
} catch (StaleKycException) {
    // Ask the resident to download a fresh file
}

$kyc->matchesMobile('+91 98765 43210'); // bool
$kyc->matchesEmail('[email protected]');  // bool

$reader = OfflineKycReader::create([Fixtures::certificateFile()]);

$reader->verifySecureQr(Fixtures::secureQr(['name' => 'Ravi Kumar']));