All Projects → jenssegers → Optimus

jenssegers / Optimus

Licence: mit
🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.

Projects that are alternatives of or similar to Optimus

Laravel Fakeid
Automatic model ID obfuscation in routes for Laravel
Stars: ✭ 161 (-85.15%)
Mutual labels:  hashids, laravel, obfuscation
Laravel Hashslug
Package providing a trait to use Hashids on a model
Stars: ✭ 136 (-87.45%)
Mutual labels:  hashids, laravel
Laravel Hashids
A Hashids bridge for Laravel
Stars: ✭ 1,714 (+58.12%)
Mutual labels:  hashids, laravel
hashids.pm
Hashids, ported for Perl
Stars: ✭ 15 (-98.62%)
Mutual labels:  hashids, ids
Laravel Optimus
Transform your internal id's to obfuscated integers based on Knuth's integer hash. Laravel wrapper for the Optimus Library by Jens Segers with multiple connections support.
Stars: ✭ 119 (-89.02%)
Mutual labels:  hashids, laravel
Hashids.js
A small JavaScript library to generate YouTube-like ids from numbers.
Stars: ✭ 3,525 (+225.18%)
Mutual labels:  ids, hashids
Eloquent Hashids
On-the-fly hashids for Laravel Eloquent models. (🍰 Easy & ⚡ Fast)
Stars: ✭ 196 (-81.92%)
Mutual labels:  hashids, laravel
id-mask
IDMask is a Java library for masking internal ids (e.g. from your DB) when they need to be published to hide their actual value and to prevent forging. It has support optional randomisation has a wide support for various Java types including long, UUID and BigInteger. This library bases its security on strong cryptographic primitives.
Stars: ✭ 39 (-96.4%)
Mutual labels:  hashids, obfuscation
idy
👓 An ID obfuscator for ActiveRecord
Stars: ✭ 15 (-98.62%)
Mutual labels:  hashids, obfuscation
harsh
Hashids implementation in Rust
Stars: ✭ 48 (-95.57%)
Mutual labels:  hashids, ids
Hashids
A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
Stars: ✭ 4,596 (+323.99%)
Mutual labels:  ids, hashids
Laravel Hashid
Obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.
Stars: ✭ 354 (-67.34%)
Mutual labels:  hashids, laravel
Laravel Hashids
Integrate Hashids with Laravel. Automatic model binding and id resolving included!
Stars: ✭ 8 (-99.26%)
Mutual labels:  hashids, laravel
Laravel Wang Editor
wangEditor for Laravel
Stars: ✭ 52 (-95.2%)
Mutual labels:  laravel
Nova Route Viewer
Route viewer tool for Laravel Nova
Stars: ✭ 54 (-95.02%)
Mutual labels:  laravel
Metamorph
Morphing mod for Minecraft 1.12.2
Stars: ✭ 52 (-95.2%)
Mutual labels:  transformations
Laravel Oauth
Social OAuth authentication for Laravel 5 & 6. Drivers: Facebook, Twitter, Google, LinkedIn, Github, Bitbucket.
Stars: ✭ 52 (-95.2%)
Mutual labels:  laravel
Wl Bootstrap
Integrating Laravel into WordPress
Stars: ✭ 54 (-95.02%)
Mutual labels:  laravel
Laravel Janitor
🔑 Easily add login proxy to your Laravel API
Stars: ✭ 54 (-95.02%)
Mutual labels:  laravel
Laravel5.7 Vue Cli3 Boilerplate
Boilerplate / Starter kit. Laravel 5.7, Vue CLI 3 — Authentication with Email Verification. REST API.
Stars: ✭ 52 (-95.2%)
Mutual labels:  laravel

Optimus id transformation

Latest Stable Version Build Status Coverage Status

With this library, you can transform your internal id's to obfuscated integers based on Knuth's integer hash. It is similar to Hashids, but will generate integers instead of random strings. It is also super fast.

Installation

Install using composer:

composer require jenssegers/optimus

If you will be running your code on a 32 bit system or will be working with large prime numbers it is suggested that you install the GMP extension. For debian/ubuntu you can install the extension with one of these commands:

apt-get install php7.0-gmp
apt-get install php7.1-gmp
apt-get install php7.2-gmp

Usage

To get started you will need 3 things;

  • Large prime number lower than 2147483647
  • The inverse prime so that (PRIME * INVERSE) & MAXID == 1
  • A large random integer lower than 2147483647

Luckily for you, I have included a console command that can do all of this for you. To get started, just run the following command:

> php vendor/bin/optimus spark

Prime: 2123809381
Inverse: 1885413229
Random: 146808189

If you prefer to choose your own prime number (from this list for example), you can pass it to the command to calculate the remaining numbers:

> php vendor/bin/optimus spark 1580030173

Prime: 1580030173
Inverse: 59260789
Random: 1163945558

Using those numbers, you can start creating instances of Optimus($prime, $inverted, $random):

use Jenssegers\Optimus\Optimus;

new Optimus(1580030173, 59260789, 1163945558);

NOTE: Make sure that you are using the same constructor values throughout your entire application!

Encoding and decoding

To encode id's, use the encode method:

$encoded = $optimus->encode(20); // 1535832388

To decode the resulting 1535832388 back to its original value, use the decode method:

$original = $optimus->decode(1535832388); // 20

Framework Integrations

Laravel

This is an example service provider which registers a shared Optimus instance for your entire application:

<?php

namespace App\Providers;

use Jenssegers\Optimus\Optimus;
use Illuminate\Support\ServiceProvider;

class OptimusServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(Optimus::class, function ($app) {
            return new Optimus(1580030173, 59260789, 1163945558);
        });
    }
}

Once you have created the service provider, add it to the providers array in your config/app.php configuration file:

App\Providers\OptimusServiceProvider::class,

Laravel's automatic injection will pass this instance where needed. Example controller:

<?php

namespace App\Http\Controllers;

use Jenssegers\Optimus\Optimus;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function show($id, Optimus $optimus)
    {
        $id = $optimus->decode($id);
    }
}

More information: https://laravel.com/docs/5.3/container#resolving

Third-party integrations

An integration with Laravel is provided by the propaganistas/laravel-fakeid package.

Laravel Optimus with multiple connections provided by the cybercog/laravel-optimus package.

An integration with Silex 2 is provided by the jaam/silex-optimus-provider package.

An integration with Laravel is provided by the elfsundae/laravel-hashid package.

A PSR-15 middleware provided by the icanhazstring/optimus-middleware package.

Security contact information

To report a security vulnerability, follow these steps.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].