PHPackages                             craftwork/id-obfuscator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. craftwork/id-obfuscator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

craftwork/id-obfuscator
=======================

A base converter to obfuscate database IDs in front end applications

1.0.0(8y ago)4902MITPHPPHP ^7.0

Since Oct 7Pushed 8y ago2 watchersCompare

[ Source](https://github.com/craftwork/id-obfuscator)[ Packagist](https://packagist.org/packages/craftwork/id-obfuscator)[ Docs](https://github.com/craftwork/id-obfuscator)[ RSS](/packages/craftwork-id-obfuscator/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

ID Obfuscator
=============

[](#id-obfuscator)

[![Build status](https://camo.githubusercontent.com/098989aab9c1d772cd85db033abe6ea5c9d8dcc230d00d360d9fbacc3d983604/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6372616674776f726b2f69642d6f626675736361746f722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/craftwork/id-obfuscator.svg?branch=master)[![Code coverage](https://camo.githubusercontent.com/3beb330f44cf238c57b0bbf80a46313e5a1e174c17860eb545efb389552c6297/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6372616674776f726b2f69642d6f626675736361746f722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/craftwork/id-obfuscator)[![Code quality](https://camo.githubusercontent.com/aa2d607679437a24a839c6aadd98a98d800f879d089f64a08b323d491cdcbfae/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6372616674776f726b2f69642d6f626675736361746f722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/craftwork/id-obfuscator)[![Packagist](https://camo.githubusercontent.com/4832dcaafa8e423e0507cddd877eb58e2b6a3649bc8d7bada200bafdab9e49bc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372616674776f726b2f69642d6f626675736361746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/craftwork/id-obfuscator)[![Chat](https://camo.githubusercontent.com/f8d9da96490aa57d7276be058339575d9a02990b35c7533dec59a33405fa79dc/68747470733a2f2f696d672e736869656c64732e696f2f6769747465722f726f6f6d2f6e776a732f6e772e6a732e7376673f7374796c653d666c61742d737175617265)](https://gitter.im/craftwork/Lobby)

A simple encoder to obfuscate database IDs.

This is particularly useful when you don't want to expose sensitive information about your application, for instance the number of users or orders.

Imagine having URLs like these:

```
http://example.com/user/5
http://example.com/order/2835

```

then you can convert them into:

```
http://example.com/user/J
http://example.com/order/3l

```

Note
----

[](#note)

This is not an encryption library and should not be used for security purposes.

It is not advisable saving encoded numbers but encoding and decoding IDs on the fly.

You can use a custom character set and a salt to shuffle the characters. Keep the salt private.

It is not advisable to change these at run time as some users might share or bookmark links. To ensure users don't end up on broken links always use the same character set and salt. If the links are restricted to logged in users it might be a good idea to use a user specific salt, such as a uuid.

Installation
------------

[](#installation)

```
$ composer require craftwork/id-obfuscator

```

Requirements
------------

[](#requirements)

PHP 7.0.

Usage
-----

[](#usage)

```
$salt = 'test';
$obfuscator = new IdObfuscator($salt);
$obfuscator->encode(10); // m
$obfuscator->encode(1234566); // oK-k

$obfuscator->decode('m'); // 10
$obfuscator->decode('oK-k'); // 1234566
```

### Character sets

[](#character-sets)

The default character set is `bcdefghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ1234567890-_`. An additional character set is also built in which only uses lowercase hexadecimal characters (`CharacterSet::ofHexCharacters()`).

You can provide your own character set if you want to either limit the encoding to certain characters or use different characters. Characters need to be ASCII and the character set must be at least two characters long and not contain any duplicates.

```
$salt = 'test';
$customCharacterSet = CharacterSet::ofCustomCharacters('ambidextrously');
$obfuscator = new IdObfuscator($salt, $customCharacterSet);
$obfuscator->encode(16); // 10 (string)
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3187d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b9a04df9c95c6ea94aab729c0e2fd7b44203e22b6d81177c4810c152728c4db3?d=identicon)[amneale](/maintainers/amneale)

![](https://avatars.githubusercontent.com/u/1458882?v=4)[Matthew Hotchen](/maintainers/mhotchen)[@mhotchen](https://github.com/mhotchen)

---

Top Contributors

[![mhotchen](https://avatars.githubusercontent.com/u/1458882?v=4)](https://github.com/mhotchen "mhotchen (6 commits)")[![amneale](https://avatars.githubusercontent.com/u/10009435?v=4)](https://github.com/amneale "amneale (4 commits)")[![fra-c](https://avatars.githubusercontent.com/u/8685269?v=4)](https://github.com/fra-c "fra-c (1 commits)")[![gadgetdave](https://avatars.githubusercontent.com/u/3147607?v=4)](https://github.com/gadgetdave "gadgetdave (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/craftwork-id-obfuscator/health.svg)

```
[![Health](https://phpackages.com/badges/craftwork-id-obfuscator/health.svg)](https://phpackages.com/packages/craftwork-id-obfuscator)
```

###  Alternatives

[laravelha/generator

Laravelha Generator

225.1k](/packages/laravelha-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
