Crypto

Lightpack’s Crypto utility provides secure, easy-to-use methods for encryption, decryption, token generation, and hashing. It is designed for safe handling of sensitive data using modern cryptography standards.


Overview


Configuration & Usage

App Key Requirement

Your .env file must have an APP_KEY set. The CryptoProvider will throw if missing.

APP_KEY=your-secret-key

You can auto-generate APP_KEY using following command:

php console app:key

Accessing the Utility

use Lightpack\Utils\Crypto;

$crypto = new Crypto($key); // Manual instantiation
$crypto = crypto();         // Preferred: via container helper

Encrypting & Decrypting Data

$encrypted = crypto()->encrypt('Sensitive data');
$decrypted = crypto()->decrypt($encrypted); // 'Sensitive data'

Generating Tokens

$token = crypto()->token(); // 64-char secure token

Hashing Data

$hash = crypto()->hash('my data');

Helper Function

You can use the global crypto() helper anywhere in your app:

crypto()->encrypt('secret');
crypto()->decrypt($encrypted);
crypto()->token();
crypto()->hash('data');

Error Handling & Security