License key generation and validation on website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

License key generation and validation implementation on website

A license key is a string that encodes rights: which product, which plan, expiration date. Validation must work both online (API) and offline (cryptographic signature verification).

Key formats

Simple random key: A3K7M-XQ2WP-N8VLR-5HZTB-J4YCS

Stores only uniqueness. All license data is on server. Online validation is mandatory.

Key with data (Partial Key Verification): Part of key encodes license attributes. Allows partial offline validation.

JWT token: eyJhbGciOiJSUzI1NiJ9... — full token with payload and RSA signature.

JWT license generation

Asymmetric RSA signature allows client application to verify license without contacting server, using only public key:

use Firebase\JWT\JWT;

class LicenseTokenService
{
    public function issue(License $license): string
    {
        $privateKey = file_get_contents(storage_path('keys/license_private.pem'));

        return JWT::encode([
            'iss'        => 'example.com',
            'iat'        => now()->timestamp,
            'exp'        => $license->expires_at?->timestamp ?? 9999999999,
            'license_id' => $license->id,
            'product'    => $license->product_code,
            'plan'       => $license->plan,
            'seats'      => $license->max_seats,
            'features'   => $license->features,
        ], $privateKey, 'RS256');
    }

    public function verify(string $token): array
    {
        $publicKey = file_get_contents(storage_path('keys/license_public.pem'));
        $payload   = JWT::decode($token, new Key($publicKey, 'RS256'));
        return (array) $payload;
    }
}

Offline validation in application

// C# example for desktop application
public class LicenseChecker
{
    private readonly string publicKey = @"-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQEAr...
-----END PUBLIC KEY-----";

    public LicenseResult Validate(string token)
    {
        var handler   = new JwtSecurityTokenHandler();
        var validation = new TokenValidationParameters
        {
            ValidateIssuer           = true,
            ValidIssuer              = "example.com",
            ValidateIssuerSigningKey = true,
            IssuerSigningKey         = GetPublicKey(),
            ValidateLifetime         = true,
        };

        try
        {
            var principal = handler.ValidateToken(token, validation, out _);
            return new LicenseResult { IsValid = true, Plan = GetClaim(principal, "plan") };
        }
        catch (SecurityTokenExpiredException)
        {
            return new LicenseResult { IsValid = false, Error = "License expired" };
        }
    }
}

Validation API

Route::post('/api/v1/licenses/validate', function (Request $request) {
    $key = $request->input('key');

    $license = License::where('key', $key)->first();

    if (!$license) {
        return response()->json(['valid' => false, 'error' => 'Invalid key'], 404);
    }

    $checks = [
        'active'     => $license->status === 'active',
        'not_expired'=> !$license->expires_at || now()->isBefore($license->expires_at),
        'seats_ok'   => $license->activations()->where('revoked', false)->count() < $license->max_activations,
    ];

    $valid = !in_array(false, $checks);

    return response()->json([
        'valid'      => $valid,
        'product'    => $license->product_code,
        'plan'       => $license->plan,
        'expires_at' => $license->expires_at,
        'errors'     => array_keys(array_filter($checks, fn($v) => !$v)),
    ]);
});

Timeline

License key generation and validation with JWT and API: 4–6 working days.