oyedele/crypto-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

oyedele/crypto-helper

最新稳定版本:v1.0.0

Composer 安装命令:

composer require oyedele/crypto-helper

包简介

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

README 文档

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.

统计信息

  • 总下载量: 223
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固