oyedele/crypto-helper

This is a Laravel/PHP helper function for encryption and decryption of data using OPENSSL

Maintainers

Package info

github.com/itz4mesays/CryptoHelper

pkg:composer/oyedele/crypto-helper

Statistics

Installs: 205

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2025-09-09 09:54 UTC

This package is auto-updated.

Last update: 2026-03-13 01:24:15 UTC


README

A lightweight PHP/Laravel package for handling encryption and decryption with OpenSSL. Supports both Laravel integration (via Service Provider & config publishing) and standalone PHP usage.

Installation

1. Require the package via Composer

composer require oyedele/crypto-helper

2. (Laravel Only) Register the Service Provider

If you are using Laravel 5.5+, the service provider is auto-discovered. For older versions, add the following to config/app.php:

'providers' => [
    // ...
    Oyedele\CryptoHelper\CryptoHelperServiceProvider::class,
];

3. (Laravel Only) Publish the Config

php artisan vendor:publish --tag=config

This will create a file at:

config/crypto-helper.php

Default config:

return [
    'cipher'  => 'AES-128-ECB',
    'options' => OPENSSL_RAW_DATA,
];

⚡ Usage

Laravel Example

use Oyedele\CryptoHelper\CryptoHelper;

// Encrypt
$encrypted = CryptoHelper::encrypt('my-secret-data', 'my-secret-key');

// Decrypt
$decrypted = CryptoHelper::decrypt($encrypted, 'my-secret-key');

echo $decrypted; // "my-secret-data"

You can also set the default key in config/crypto-helper.php or at runtime:

config(['crypto-helper.key' => 'my-default-key']);

$encrypted = CryptoHelper::encrypt('data'); // uses default key

Standalone PHP Example

When using outside Laravel, configuration falls back to the built-in Config class.

require 'vendor/autoload.php';

use Oyedele\CryptoHelper\Config;
use Oyedele\CryptoHelper\CryptoHelper;

// Set encryption key globally
Config::set('key', 'my-standalone-key');

// Encrypt
$encrypted = CryptoHelper::encrypt('standalone-data');

// Decrypt
$decrypted = CryptoHelper::decrypt($encrypted);

echo $decrypted; // "standalone-data"

Configuration Options

Key Description Default
cipher OpenSSL cipher algorithm AES-128-ECB
options OpenSSL options (e.g., OPENSSL_RAW_DATA) OPENSSL_RAW_DATA
key Encryption key (set manually or via config) null

Testing

Run PHPUnit tests:

vendor/bin/phpunit

Package Structure

crypto-helper/
├── config/
│   └── crypto-helper.php       # Default config
├── src/
│   ├── Config.php              # Standalone config manager
│   ├── CryptoHelper.php        # Core encryption/decryption
│   └── CryptoHelperServiceProvider.php # Laravel provider
├── tests/
│   └── CryptoHelperTest.php    # PHPUnit tests
└── README.md

License

This package is open-sourced software licensed under the MIT license.