claudye/php-crypter

通过加密确保您网站的数据安全。只有在使用您秘密密钥的应用程序中才能解密

v1.0 2022-09-01 00:26 UTC

This package is auto-updated.

Last update: 2024-09-30 01:41:11 UTC


README

通过加密确保您网站的数据安全。只有在使用您秘密密钥的应用程序中才能解密

如何安装?

使用composer

  • 首先您需要composer
  • 运行命令 composer require claudye/php-crypter

从github克隆或下载

  • github 克隆或下载
  • 确保您已安装 composer
  • 转到您项目的根目录并打开那里的shell(终端)
  • 运行 composer install

用法

当php crypter成功安装后,请导入加密类,例如

use PHPCrypter\Encryption\Encryption;

  • 要加密数据,您使用 Encryption::encrypt(string $text, string $algo_method="AES-128-CBC", string $token=null) 此方法需要加密的数据,其他参数是可选的。它返回您可以存储或写入某处的加密数据以便重复使用
  • 要稍后解密加密信息,您可以使用方法 Encryption::decrypt(string $data_encrypted) 此方法将使用为您生成的密钥来解密加密的数据。此密钥必须是秘密的

示例

 

  use PHPCrypter\Encryption\Encryption;
  //You can define your key any where you want 

  //define("ENC_TOKEN_PATH", "your/dir/example");

  require 'vendor/autoload.php';
  // Encrypt the text "The only limit of a developer is his imagination" 

$encrypt = Encryption::encrypt("The only limit of a developer is his imagination"); //You store the encrypted data in a file or in a database, or any where you can reuse it
//After you want to use it again on your site
//Get your text: $encrypt and then decrypt it
$decrypt = Encryption::decrypt($encrypt); //All right !

更改加密密钥路径!

您可以选择更改存储秘密密钥的加密密钥路径(文件或目录)!选择非常安全的路径是个好主意。您只需在项目中定义一个名为: ENC_TOKEN_PATH 的常量,让我们的脚本可以找到它即可

信息

默认使用的加密方法是: AES-128-CBC 在这里找到所有方法

注意!

当您使用密钥加密数据时,只有此密钥才能解密它,所以请务必不要丢失密钥或随意更改密钥。