PHPackages                             jedisct1/ipcrypt - 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. [Security](/categories/security)
4. /
5. jedisct1/ipcrypt

ActiveLibrary[Security](/categories/security)

jedisct1/ipcrypt
================

IP Address Encryption and Obfuscation

v0.9.0(1y ago)76MITPHPPHP &gt;=8.2CI passing

Since Apr 23Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/jedisct1/php-ipcrypt)[ Packagist](https://packagist.org/packages/jedisct1/ipcrypt)[ RSS](/packages/jedisct1-ipcrypt/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

IPcrypt PHP Implementation
==========================

[](#ipcrypt-php-implementation)

This is a PHP implementation of IPcrypt, which provides methods for encrypting and decrypting IP addresses. The implementation follows the [IPcrypt specification](https://datatracker.ietf.org/doc/draft-denis-ipcrypt/) and provides three different encryption modes.

Features
--------

[](#features)

- Deterministic encryption (using AES-128)
- Non-deterministic encryption (using KIASU-BC)
- XEX-mode encryption (using AES-XTS)
- Support for both IPv4 and IPv6 addresses (with IPv4-mapped IPv6 handling)
- Secure key generation for all modes
- Comprehensive test suite with test vectors from the specification
- PSR-12 compliant code style
- Extensive test coverage for core functionality

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

[](#requirements)

- PHP 8.2 or higher
- OpenSSL extension (for AES operations)
- Composer (for installation and development)

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

[](#installation)

```
composer require jedisct1/ipcrypt
```

Usage
-----

[](#usage)

### Deterministic Encryption (ipcrypt-deterministic)

[](#deterministic-encryption-ipcrypt-deterministic)

Uses AES-128 to provide deterministic encryption. The same input will always produce the same output when using the same key.

```
use Ipcrypt\IpcryptDeterministic;

// Generate a random 16-byte key
$key = IpcryptDeterministic::generateKey();

// Example with IPv4
$ipv4 = '192.0.2.1';
$encrypted = IpcryptDeterministic::encrypt($ipv4, $key);
$decrypted = IpcryptDeterministic::decrypt($encrypted, $key);

// Example with IPv6
$ipv6 = '2001:db8::1';
$encrypted = IpcryptDeterministic::encrypt($ipv6, $key);
$decrypted = IpcryptDeterministic::decrypt($encrypted, $key);
```

### Non-deterministic Encryption (ipcrypt-nd)

[](#non-deterministic-encryption-ipcrypt-nd)

Uses KIASU-BC to provide non-deterministic encryption. Each encryption operation uses a random tweak value to produce different ciphertexts for the same input.

```
use Ipcrypt\IpcryptNd;

// Generate a random 16-byte key
$key = IpcryptNd::generateKey();

$ip = '192.0.2.1';

// Each encryption produces a different result
$encrypted1 = IpcryptNd::encrypt($ip, $key);  // Uses random 8-byte tweak
$encrypted2 = IpcryptNd::encrypt($ip, $key);  // Different result
echo $encrypted1 !== $encrypted2; // true

// Both decrypt to the same IP
$decrypted1 = IpcryptNd::decrypt($encrypted1, $key);
$decrypted2 = IpcryptNd::decrypt($encrypted2, $key);
echo $decrypted1 === $decrypted2; // true
```

### XTS-mode Encryption (ipcrypt-ndx)

[](#xts-mode-encryption-ipcrypt-ndx)

Uses AES-XTS mode to provide non-deterministic encryption with enhanced security properties. Requires a 32-byte key (two AES-128 keys).

```
use Ipcrypt\IpcryptNdx;

// Generate a random 32-byte key (two AES-128 keys)
$key = IpcryptNdx::generateKey();

$ip = '192.0.2.1';

// Each encryption produces a different result
$encrypted1 = IpcryptNdx::encrypt($ip, $key);  // Uses random 16-byte tweak
$encrypted2 = IpcryptNdx::encrypt($ip, $key);  // Different result
echo $encrypted1 !== $encrypted2; // true

// Both decrypt to the same IP
$decrypted1 = IpcryptNdx::decrypt($encrypted1, $key);
$decrypted2 = IpcryptNdx::decrypt($encrypted2, $key);
echo $decrypted1 === $decrypted2; // true
```

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

The project includes a comprehensive test suite with test vectors from the IPcrypt specification:

```
composer install  # Install dependencies
composer test    # Run PHPUnit tests
```

Current test status: ✅ 60 tests, 137 assertions - all passing

### Examples

[](#examples)

Complete working examples can be found in the `examples/` directory.

### Code Style

[](#code-style)

The code follows PSR-12 coding standards. To check and fix code style:

```
composer cs      # Check code style
composer cs-fix  # Automatically fix code style issues
```

### Type Safety

[](#type-safety)

The codebase uses PHP 8.2+ type hints throughout:

- Parameter and return type declarations
- Property type declarations
- Strict type checking enabled
- Comprehensive PHPDoc blocks with type information

Implementation Details
----------------------

[](#implementation-details)

### IP Address Handling

[](#ip-address-handling)

- IPv4 addresses are converted to IPv4-mapped IPv6 addresses internally
- All operations work on 16-byte blocks (IPv6 address size)
- Automatic detection and conversion between IPv4 and IPv6 formats

### Security Features

[](#security-features)

- Built-in secure key generation for each mode
- Secure random number generation for tweaks
- No padding required (fixed-size inputs)
- Constant-time operations where possible
- Input validation for all parameters
- Regular security scans via GitHub Actions

### Key Generation

[](#key-generation)

Each implementation provides a secure key generation method:

- `IpcryptDeterministic::generateKey()`: Generates a 16-byte key for AES-128
- `IpcryptNd::generateKey()`: Generates a 16-byte key for KIASU-BC
- `IpcryptNdx::generateKey()`: Generates a 32-byte key (two AES-128 keys) for XTS mode

### Continuous Integration

[](#continuous-integration)

The project uses GitHub Actions for:

- Automated testing on various PHP versions
- Code style checking (PSR-12)
- Security vulnerability scanning
- Test coverage reporting

License
-------

[](#license)

MIT License. See LICENSE file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance58

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

437d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/124872?v=4)[Frank Denis](/maintainers/jedisct1)[@jedisct1](https://github.com/jedisct1)

---

Top Contributors

[![jedisct1](https://avatars.githubusercontent.com/u/124872?v=4)](https://github.com/jedisct1 "jedisct1 (6 commits)")

---

Tags

addresscomposerencryptionipipcryptipcrypt2obfuscationphp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jedisct1-ipcrypt/health.svg)

```
[![Health](https://phpackages.com/badges/jedisct1-ipcrypt/health.svg)](https://phpackages.com/packages/jedisct1-ipcrypt)
```

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.7M143](/packages/mews-purifier)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24820.0k38](/packages/paragonie-ecc)[laravelgems/blade-escape

Custom blade directives to figth against XSS

1212.5k](/packages/laravelgems-blade-escape)

PHPackages © 2026

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