rnr1721/le7-cryptography

加密学是一个轻量级的PHP库,用于密码加密、解密、验证和随机密码生成。这个库没有依赖,只需要PHP的OpenSSL扩展

1.0.0 2024-05-12 16:03 UTC

This package is auto-updated.

Last update: 2024-09-12 16:47:07 UTC


README

Le7 加密学是一个轻量级的PHP库,用于密码加密、解密、验证和随机密码生成。这个库没有依赖,只需要PHP的OpenSSL扩展

一个小型的PHP库,用于安全地加密、解密、验证密码和生成随机密码。它仅依赖于PHP的OpenSSL扩展,没有其他依赖。

特性

  • 强加密:使用OpenSSL进行强密码加密和解密,支持多种算法,如AES-128、AES-192、AES-256和DES-EDE3。
  • 密码生成:生成可自定义长度的随机密码,允许指定密码生成的字符集。
  • 密码验证:验证提供的密码是否与之前加密的密码匹配,确保安全的身份验证。

要求

  • PHP 8.0或更高版本
  • PHP ext-openssl
  • composer

安装

要安装加密学库,只需克隆存储库或下载源文件,并将它们包含到您的PHP项目中。

git clone https://github.com/username/repository.git

使用

您可以直接在创建类对象时指定密钥,或者在每次加密/解密操作中使用自定义密钥。

// Include the Cryptography class
use rnr1721\Core\Cryptography;

// Initialize Cryptography with a key and method (optional)
$crypto = new Cryptography('your_secret_key', 'AES-256-CBC');

// Encrypt a password
$encryptedPassword = $crypto->encryptPassword('my_password');

// Decrypt an encrypted password
$decryptedPassword = $crypto->decryptPassword($encryptedPassword);

// Generate a random password
$randomPassword = $crypto->generateRandomPassword();

// Verify a password against its encrypted counterpart
$isPasswordValid = $crypto->verifyPassword('my_password', $encryptedPassword);

或者您可以使用密钥进行每个操作

// Include the Cryptography class
use rnr1721\Core\Cryptography;

// Initialize Cryptography with a key and method (optional)
$crypto = new Cryptography();

// Encrypt a password
$encryptedPassword = $crypto->encryptPassword('my_password','your_secret_key','AES-256-CBC');

// Decrypt an encrypted password
$decryptedPassword = $crypto->decryptPassword($encryptedPassword,'your_secret_key','AES-256-CBC');

// Generate a random password. Length is optional, default is 7
$randomPassword = $crypto->generateRandomPassword(7);

// Verify a password against its encrypted counterpart
$isPasswordValid = $crypto->verifyPassword('my_password', $encryptedPassword,'your_secret_key','AES-256-CBC');

您还可以设置用于随机密码生成的符号

// Include the Cryptography class
use rnr1721\Core\Cryptography;

// Initialize Cryptography with a key and method (optional)
$crypto = new Cryptography('your_secret_key', 'AES-256-CBC');

$crypto->setDefaultPasswordChars('abcdefgh');

$newPassword = $crypto->generateRandomPassword(5);

您还可以获取允许的方法数组

// Include the Cryptography class
use rnr1721\Core\Cryptography;
$crypto = new Cryptography('your_secret_key', 'AES-256-CBC');
$allowedMethods = $crypto->getAllowedMethods();

贡献

欢迎贡献!请随时提交错误报告、功能请求或拉取请求。对于重大更改,请首先提交一个问题以讨论拟议的更改。

许可证

本项目采用MIT许可证 - 有关详细信息,请参阅LICENSE文件。