inanepain/crypt
最新稳定版本:0.1.0
Composer 安装命令:
composer require inanepain/crypt
包简介
Encryption helpers and password hashers.
README 文档
README
Table of Contents
inanepain/crypt
Encryption helpers and password hashers.
1. Install
composercomposer 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.
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).
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.
$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.
$secret = new Secret($passphrase, 'aes-128-cbc', 'my-custom-iv-123');
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: UNLICENSE
- 更新时间: 2026-04-15