talentrydev/cryptography

PHP 加密库

2.0.0 2024-05-31 13:26 UTC

This package is auto-updated.

Last update: 2024-08-31 00:44:00 UTC


README

这是一个轻量级的库,用于加密和解密字符串以及生成哈希值。

安装

  • 运行
composer require talentrydev/cryptography

使用示例

加密/解密

$factory = new \Talentry\Cryptography\Factory\EncryptionServiceFactory();
$encryptionKey = $factory->generateEncryptionKey();
$service = $factory->generateEncryptionService($encryptionKey);
$encryptedString = $service->encrypt('secret');
$decryptedString = $service->decrypt($encryptedString);

警告:encrypt 方法不是幂等的。用相同的输入多次调用它将返回不同的输出。唯一保证的是,解密加密的字符串将始终返回原始(未加密)的字符串。

生成哈希值

$factory = new \Talentry\Cryptography\Factory\HashGeneratorFactory();
$hash = $factory->generate('input');

开发

  • 安装依赖项: make deps
  • 运行测试: make test