commandstring/encrypt

加密数据的一种更简单的方式

v3.0.1 2023-12-02 22:41 UTC

This package is auto-updated.

Last update: 2024-10-01 00:08:18 UTC


README

使用Composer安装:composer require CommandString/Encrypt

要求

  • PHP >=8.0
  • 基本的PHP OOP理解
  • Composer 2

基本用法

require __DIR__"/vendor/autoload.php";
use CommandString/Encrypt/Encryption;

#                            v >=32 character string            v Encryption method #
$encryptor = new Encryption("MZCdg02STLzrsj05KE3SIL62SSlh2Ij", "AES-256-CTR");

$encryptedString = $encryptor->encrypt("Hello World"); // 2aPpxvxiUc3W3TCK:xJmkuSYDpOIOX9k=
$decryptedString = $encryptor->decrypt($encryptedString"); // Hello World

比较CommandString/Encrypt与常规加密

CommandString/Encrypt

// config.php
require __DIR__"/vendor/autoload.php";
use CommandString/Encrypt/Encryption;

$encryptor = new Encryption("MZCdg02STLzrsj05KE3SIL62SSlh2Ij", "AES-256-CTR");
// ...

// somepage.php
require_once "config.php";

$var = /* some value that needs encrypted */;
$encryptedVar = $encryptor->encrypt($var);
// ...

// someotherpage.php
require_once "config.php";

$encryptedVar = /* retrieved encryptedVar from somepage.php */;
$decryptedVar = $encryptor->decrypt($encryptedVar);
//...