northlands/permuteseq

A small PHP library to obfuscate numbers.

v0.2 2022-09-05 10:28 UTC

This package is auto-updated.

Last update: 2025-01-14 14:55:53 UTC


README

A small PHP library to obfuscate numbers. Use it when you don't want to expose your database numeric ids to users.

The permutations are collision-free and fully deterministic. The random-looking effect is due to encryption, not to a PRNG. The same boundary range with the same secret key will always produce the same output.

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Installation

You can install the package via composer:

composer require northlands/permuteseq

Usage

$permuteseq = new Permuteseq(123456789012345, 1000, 9999); // Range 1000-9999

$encoded = $permuteseq->encode(1000); // 1446
$decoded = $permuteseq->decode($encoded); // 1000

Testing

composer test

In order to ensure compability with the Postgres extension, an integration test is included:

vendor/bin/pest --group=integration

The integration test requires a running Postgres database with the extension installed:

docker build -t postgres tests
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=local -d postgres

psql> CREATE EXTENSION permuteseq;

Changelog

Please see CHANGELOG for more information on what has changed recently.

Disclaimer

The library should not be considered cryptographically strong or used to sensitive data.

Credits

Alternatives

License

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