PHPackages                             timefrontiers/php-data - 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. timefrontiers/php-data

ActiveLibrary[Security](/categories/security)

timefrontiers/php-data
======================

PHP Data utilities - encryption, hashing, random generation

v1.0.4(3w ago)0273MITPHPPHP &gt;=8.1

Since Apr 15Pushed 3w agoCompare

[ Source](https://github.com/timefrontiers/php-data)[ Packagist](https://packagist.org/packages/timefrontiers/php-data)[ Docs](https://github.com/timefrontiers/php-data)[ RSS](/packages/timefrontiers-php-data/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)Dependencies (1)Versions (5)Used By (3)

TimeFrontiers PHP Data
======================

[](#timefrontiers-php-data)

PHP data utilities — encryption, password hashing, random generation, and more.

[![PHP Version](https://camo.githubusercontent.com/04744bae0a61d2ffe29c26f07a9612eae20445fc6feaeb77b3af1f0e9be6447c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

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

[](#installation)

```
composer require timefrontiers/php-data
```

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

[](#requirements)

- PHP 8.1+
- ext-openssl

Quick Start
-----------

[](#quick-start)

```
use TimeFrontiers\Data\{Encryption, Password, Random, Signer};

// Encryption
$enc = new Encryption('/secure/path/my.key');
$encrypted = $enc->encrypt('sensitive data');
$decrypted = $enc->decrypt($encrypted);

// Password hashing
$hash = Password::hash('secret123');
$valid = Password::verify('secret123', $hash);

// Random strings
$token = Random::alphanumeric(32);
$code = Random::numeric(6);

// String signing
Signer::setKey('your-secret-key');
$signed = Signer::sign('user_id=123');
$original = Signer::verify($signed);
```

Classes
-------

[](#classes)

ClassPurpose`Encryption`AES-256-CBC encryption/decryption`Password`Modern password hashing (Argon2ID)`Random`Cryptographically secure random generation`Signer`HMAC-SHA256 string signing`ByteConverter`Size unit conversions> String manipulation, HTTP responses, and phone utilities now live in [`timefrontiers/php-core`](../php-core) (`Str`, `Http\Http`, `Phone`). This package is focused strictly on data-manipulation primitives.

---

Encryption
----------

[](#encryption)

### Key Configuration

[](#key-configuration)

```
use TimeFrontiers\Data\Encryption;

// Option 1: Provide key file path
$enc = new Encryption('/secure/path/encryption.key');

// Option 2: Provide raw base64 key
$enc = new Encryption('base64-encoded-key-here');
```

A key **must** be supplied. There is no implicit fallback path — calling `new Encryption()` without a prior `setKeyFile()` will throw.

### Static Configuration

[](#static-configuration)

```
// Configure once at bootstrap
Encryption::setKeyFile('/secure/path/encryption.key');

// Then use static methods anywhere
$encrypted = Encryption::enc($data);
$decrypted = Encryption::dec($encrypted);
```

### Usage

[](#usage)

```
$enc = new Encryption($key_file);

// Basic encrypt/decrypt
$encrypted = $enc->encrypt('secret data');
$decrypted = $enc->decrypt($encrypted);

// URL-safe (base64 encoded)
$encoded = $enc->encodeEncrypt('secret data');
$decoded = $enc->decodeDecrypt($encoded);

// Per-operation key override
$encrypted = $enc->encrypt($data, '/different/key/file');
$encrypted = $enc->encrypt($data, 'different-raw-key');

// Generate new key
$new_key = Encryption::generateKey();
```

### Key File Format

[](#key-file-format)

Key files should contain a base64-encoded 32-byte key:

```
Th1sIs4Base64EncodedKeyOf32Bytes==

```

Generate one with:

```
file_put_contents('/secure/path/my.key', Encryption::generateKey());
chmod('/secure/path/my.key', 0600);
```

---

Password
--------

[](#password)

### Modern Usage (Argon2ID)

[](#modern-usage-argon2id)

```
use TimeFrontiers\Data\Password;

// Hash a password
$hash = Password::hash('secret123');

// Verify
if (Password::verify('secret123', $hash)) {
  // Valid!
}

// Check if rehash needed (algorithm/cost changed)
if (Password::needsRehash($hash)) {
  $new_hash = Password::hash($password);
  // Update in database
}

// Or use convenience method
$result = Password::verifyAndRehash($password, $stored_hash);
if ($result['verified']) {
  if ($result['new_hash']) {
    // Update database with $result['new_hash']
  }
}
```

### Configuration

[](#configuration)

```
// Use bcrypt instead of Argon2ID
Password::configure(Password::ALGO_BCRYPT, ['cost' => 12]);

// Argon2ID with custom options
Password::configure(Password::ALGO_ARGON2ID, [
  'memory_cost' => 65536,
  'time_cost' => 4,
  'threads' => 3,
]);
```

---

Random
------

[](#random)

All methods use `random_bytes()` / `random_int()` (CSPRNG).

```
use TimeFrontiers\Data\Random;

// Strings
$alphanumeric = Random::alphanumeric(16);       // "Kj7mNp2XaB9cD4eF"
$numeric = Random::numeric(6);                   // "847293"
$hex = Random::hex(32);                          // "a1b2c3d4..."
$base64 = Random::base64(32);                    // URL-safe base64

// Without ambiguous chars (0/O, 1/I/l)
$unambiguous = Random::alphanumeric(8, false);  // "Kj7mNp2X"

// Custom character set
$custom = Random::string(10, 'ACGT');           // "ACGTACGTAC"

// Case-specific
$lower = Random::lowercase(8);
$upper = Random::uppercase(8);

// UUID v4
$uuid = Random::uuid();  // "550e8400-e29b-41d4-a716-446655440000"

// Unique ID with prefix
$id = Random::uniqueId('usr', 12);  // "usr_Kj7mNp2XaB9c"

// Random integer
$num = Random::int(1, 100);

// Pick from array
$item = Random::pick(['red', 'green', 'blue']);

// Secure shuffle
$shuffled = Random::shuffle($array);
```

---

Signer
------

[](#signer)

Sign strings to detect tampering (URLs, cookies, form data).

```
use TimeFrontiers\Data\Signer;

// Configure once at bootstrap
Signer::setKey('your-secret-key');

// Sign
$signed = Signer::sign('user_id=123');
// Returns: "user_id=123--a1b2c3d4e5f6..."

// Verify
$original = Signer::verify($signed);
// Returns: "user_id=123" or false if tampered

// Check validity
if (Signer::isValid($signed)) {
  // Signature is valid
}

// Per-operation key
$signed = Signer::sign($data, 'different-key');
```

---

ByteConverter
-------------

[](#byteconverter)

```
use TimeFrontiers\Data\ByteConverter;

// Convert to bytes
$bytes = ByteConverter::toBytes(10, 'mb');      // 10485760
$bytes = ByteConverter::mbToBytes(10);          // 10485760

// Convert from bytes
$mb = ByteConverter::fromBytes(10485760, 'mb'); // 10.0
$mb = ByteConverter::bytesToMb(10485760);       // 10.0

// Convert between units
$gb = ByteConverter::convert(1024, 'mb', 'gb'); // 1.0

// Human-readable format
ByteConverter::format(1536000);                 // "1.46 MB"

// Parse string
ByteConverter::parse('10 MB');                  // 10485760
ByteConverter::parse('1.5 GB');                 // 1610612736
```

---

Security defaults
-----------------

[](#security-defaults)

PrimitiveAlgorithmRandom generation`random_int()` / `random_bytes()` (CSPRNG)String signingHMAC-SHA256Password hashing`password_hash()` with Argon2ID (bcrypt configurable)EncryptionAES-256-CBC with random IV per messageLicense
-------

[](#license)

[MIT License](LICENSE)

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance94

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

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

Every ~9 days

Total

4

Last Release

26d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

randomphpencryptiondatahashing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/timefrontiers-php-data/health.svg)

```
[![Health](https://phpackages.com/badges/timefrontiers-php-data/health.svg)](https://phpackages.com/packages/timefrontiers-php-data)
```

###  Alternatives

[passwordlib/passwordlib

A Password Hashing Library

377222.4k7](/packages/passwordlib-passwordlib)[poly-crypto/poly-crypto

High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+

128.1k1](/packages/poly-crypto-poly-crypto)[stymiee/php-simple-encryption

The PHP Simple Encryption library is designed to simplify the process of encrypting and decrypting data while ensuring best practices are followed. By default is uses a secure encryption algorithm and generates a cryptologically strong initialization vector so developers do not need to becomes experts in encryption to securely store sensitive data.

438.8k](/packages/stymiee-php-simple-encryption)

PHPackages © 2026

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