kduma/pkv

Partial Key Verification Library for PHP

v1.0.0-beta.1 2025-09-04 12:36 UTC

README

Latest Version on Packagist Tests Total Downloads

This is a port of my other C# library Partial Key Verification Library for Compact Framework into a PHP package.

This library implements Partial Key Verification (PKV). PKV is a cryptographic technique that allows verification of a subset of a key without revealing the entire key, enhancing security and privacy in various applications.

Check full documentation here: opensource.duma.sh/libraries/php/partial-key-verification

Installation

You can install the package via composer:

composer require kduma/pkv

Usage

private static function validateKey(string $key): bool {
	$seed = \KDuma\PKV\PartialKeyValidator::getSerialNumberFromKey($key);
	$blacklist = [1518008798, 42];
	if (in_array($seed, $blacklist, true))
		return false;

	// Validation for key with index 1
	if (!\KDuma\PKV\PartialKeyValidator::validateKey(new \KDuma\PKV\Checksum\Adler16(), new \KDuma\PKV\Hash\OneAtATime(), $key, 1, 766109221))
		return false;

	// Validation for key with index 4
	if (!\KDuma\PKV\PartialKeyValidator::validateKey(new \KDuma\PKV\Checksum\Adler16(), new \KDuma\PKV\Hash\Fnv1a(), $key, 4, 4072442218))
		return false;

	return true;
}

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

Packagist

View this package on Packagist.org: kduma/pkv