Building Tamper-Evident Digital Receipts and Certificates with HMAC-SHA256 and QR Codes
Plain PDF certificates can be edited in five minutes with any PDF editor. Here is how we sign every certificate and fee receipt with HMAC-SHA256 and online QR verification.
In Pakistan's education and training sector, forged completion certificates and edited bank receipts are a real operational problem. Anyone can open a standard PDF in Illustrator or an online editor, change a student's name or paid amount, and export a convincing fake.
Solving this does not require blockchain hype or expensive third-party SaaS platforms. Standard cryptography—HMAC-SHA256 combined with a public verification endpoint and an embedded QR code—solves it cleanly inside Laravel.
Step 1: Generate a Canonical Signed Fingerprint
Instead of signing a random string, hash the exact immutable fields of the record using your server's private key. If someone changes even a single digit of the paid amount or receipt number, the signature no longer matches.
$payload = implode('|', [
(string) $payment->receipt_number,
(string) $payment->enrollment_id,
(string) $payment->amount_pkr,
(string) ($payment->verified_at?->timestamp ?? 0),
]);
$hmac = strtoupper(hash_hmac('sha256', $payload, (string) config('app.key')));
$signature = 'RU-SIG-' . substr($hmac, 0, 8) . '-' . substr($hmac, 8, 8) . '-' . substr($hmac, 16, 8);
Step 2: Embed a Direct Verification QR Code
Every PDF receipt and certificate prints a QR code pointing to a dedicated public verification URL such as https://rudigitalservices.com/verify-certificate?id=... or /receipt/{receipt_number}. When an HR manager or accountant scans the QR code on their phone, they immediately see the live database record: student name, cohort, issue date, current validity status (Valid vs. Revoked), and the matching digital signature fingerprint.
Step 3: Support Revocation Without Deleting History
Never delete a certificate row if it was issued in error or revoked for policy violations. Store an is_valid boolean, revoked_at timestamp, and revoked_reason column. When someone scans a revoked certificate's QR code, the verification page clearly displays a red Revoked status instead of a confusing 404 page.
Step 4: Protect the Verification Endpoint Against Enumeration
- Use a structured ID with a check digit or random alphanumeric suffix rather than sequential integers (
1, 2, 3). - Apply
throttle:30,1rate limiting on the verification lookup route so automated scripts cannot scrape your graduate registry. - Log every issuance and revocation in your
audit_logstable with the admin user ID and IP address.
This pattern takes less than half a day to build in Laravel and turns every document your organization issues into a verifiable credential.
Need help architecting a Laravel backend, Kotlin Android app, or joining our weekend engineering cohort?