hobocta/encrypt

使用数据加密的简单方法

v1.0.2 2018-12-11 09:36 UTC

This package is auto-updated.

Last update: 2024-09-12 04:05:34 UTC


README

Build Status codecov Latest Stable Version Latest Unstable Version License Downloads

需求

php ^5.3.3^7.0 需要 OpenSSL 或 Mcrypt 扩展

安装

composer require hobocta/encrypt

用法

use Hobocta\Encrypt\Encryptor\Fabric\EncryptorFabric;
use Hobocta\Encrypt\EncryptService;
use Hobocta\Encrypt\Stringify\Base64Stringify;

$data = 'My secret data!';

$password = '1234';

$encryptService = new EncryptService(
    (new EncryptorFabric(sha1($password)))->createEncryptor128(),
    new Base64Stringify()
);

$encrypted = $encryptService->encrypt($data); // 'fxVrDEtIb/krb8fHW6hhVDbH9VeV1Lwbs3hM35ITtc8='

$decrypted = $encryptService->decrypt($encrypted); // 'My secret data!'

运行简单示例

php examples/simple.php 代码

运行所有变体的示例

php examples/all.php

运行所有变体的性能测试

php examples/performance.php

运行单元测试

phpunit