承接 mpyw/easycrypt 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mpyw/easycrypt

最新稳定版本:v4.1.3

Composer 安装命令:

composer require mpyw/easycrypt

包简介

A class that provides simple interface for decryptable encryption.

README 文档

README

A class that provides simple interface for decryptable encryption.

Requirements

  • PHP: ^8.2

Note

Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.

Installing

composer require mpyw/easycrypt

Usage

Basic

The default cipher method is aes256 (aes-256-cbc).

<?php

use Mpyw\EasyCrypt\Cryptor;

$cryptor = new Cryptor;

$secretData = '[Secret Data]';
$password = '[Password]';

$encrypted = $cryptor->encrypt($secretData, $password);
$decrypted = $cryptor->decrypt($encrypted, $password); // String on success, false on failure.

var_dump($secretData === $decrypted); // bool(true)

Throw DecryptionFailedException when decryption failed

It throws DecryptionFailedException instead of returning false.

$decrypted = $cryptor->mustDecrypt($encrypted, $password);

Use fixed password

You can use FixedPasswordCryptor instead of raw Cryptor. This is useful when we use a fixed password from an application config.

<?php

use Mpyw\EasyCrypt\FixedPasswordCryptor;

$cryptor = new FixedPasswordCryptor('[Password]');

$secretData = '[Secret Data]';

$encrypted = $cryptor->encrypt($secretData);
$decrypted = $cryptor->decrypt($encrypted); // String on success, false on failure.

var_dump($secretData === $decrypted); // bool(true)

Use AEAD (Authenticated Encryption with Associated Data) suites

If you need to use AEAD suites that adopt CTR mode, it is recommended to provide truly unique counter value.

use Mpyw\EasyCrypt\IvGenerator\IvGeneratorInterface;

class Counter implements IvGeneratorInterface
{
    protected \PDO $pdo;

    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    public function generate(int $length): string
    {
        $this->pdo->exec('INSERT INTO counters()');
        return $this->pdo->lastInsertId();
    }
}
<?php

use Mpyw\EasyCrypt\Cryptor;

$cryptor = new Cryptor('aes-256-gcm', new Counter(new \PDO(...)));

统计信息

  • 总下载量: 4.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固