定制 inanepain/crypt 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

inanepain/crypt

最新稳定版本:0.1.0

Composer 安装命令:

composer require inanepain/crypt

包简介

Encryption helpers and password hashers.

README 文档

README

Table of Contents

icon inanepain/crypt

Encryption helpers and password hashers.

1. Install

composer
composer require inanepain/crypt

2. Crypt

This is meant as more of an introduction to the classes found in the Inane\Crypt namespace and not an in-depth guide.

Classes

3. Secret

The Secret class is a helper for encrypting and decrypting strings using OpenSSL. It also provides methods to encode the encrypted data into a URL-safe format.

3.1. Properties

properties
  • protected string $passphrase

  • protected string $cipher

  • protected ?string $iv

3.2. Methods

methods
  • public function __construct(string $passphrase, string $cipher = 'aes-256-ctr', ?string $iv = null)

  • public function encrypt(string $plainText): string

  • public function decrypt(string $encryptedText): string

  • public function encode(string $encryptedText): string

  • public function decode(string $encodedText): string

  • public function encryptEncode(string $plainText): string

  • public function decryptDecode(string $encryptedEncodedText): string

3.2.1. Usage

To use the Secret class, you need to instantiate it with a passphrase (minimum 16 characters).

Encryption and Decryption
use Inane\Crypt\Secret;

$passphrase = 'a-very-secret-phrase-of-at-least-16-chars';
$secret = new Secret($passphrase);

$originalText = 'Hello World!';

// Encrypt
$encrypted = $secret->encrypt($originalText);

// Decrypt
$decrypted = $secret->decrypt($encrypted);

echo $decrypted; // Hello World!

3.2.2. URL Safe Encoding

Encrypted data often contains characters that are not safe for URLs (like +, /, =). The encode and decode methods handle this by replacing them with URL-safe alternatives.

URL Safe Encryption
$secret = new Secret($passphrase);

$originalText = 'Sensitive Data';

// Encrypt and Encode in one go
$urlSafeEncrypted = $secret->encryptEncode($originalText);

// ... later ...

// Decode and Decrypt
$decrypted = $secret->decryptDecode($urlSafeEncrypted);

echo $decrypted; // Sensitive Data

3.2.3. Custom Cipher and IV

By default, it uses aes-256-ctr. You can specify a different cipher or provide your own IV.

Custom Cipher
$secret = new Secret($passphrase, 'aes-128-cbc', 'my-custom-iv-123');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: UNLICENSE
  • 更新时间: 2026-04-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固