定制 adbario/php-encrypter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

adbario/php-encrypter

最新稳定版本:1.0.0

Composer 安装命令:

composer require adbario/php-encrypter

包简介

Encryption with AES-256 and HMAC-SHA256

README 文档

README

This project encrypts and decrypts the given value. It uses OpenSSL extension with AES-256 cipher for encryption and HMAC-SHA-256 for hash. The encryption and hash can use different keys.

PHP Encrypter requires PHP 5.3 or higher, OpenSSL and Multibyte String extensions.

Security Notice

As a reversible operation, encryption is not a secure solution for storing passwords. Always use hashing with salt per user for passwords.

Installation

With Composer:

composer require adbario/php-encrypter

Manual installation:

  1. Download the latest release
  2. Extract the files into your project
  3. require_once '/path/to/php-encrypter/src/Encrypter.php';
  4. If your PHP version is lower than 7, also polyfill for random_bytes() is required

Usage

Setup the encryption key:

$key = '+NeXrQhAEhW}g8gf^y)Up8hAUKpue7wb';

Change the key to your own custom random 32 character string.

Create a new encrypter instance:

$encrypter = new \Adbar\Encrypter($key);

If you wish to use a different key for hashing, you can pass it to constructor as a second parameter:

$encrypter = new \Adbar\Encrypter($key, $authKey);

Encryption

Encrypt a string:

$string = 'This is my string to encrypt.';
$encrypted = $encrypter->encryptString($string);

Encrypt other variable types with serialization:

$array = array('key' => 'value');
$encrypted = $encrypter->encrypt($array);

Decryption

Decrypt a string:

$string = $encrypter->decryptString($encrypted);

Decrypt other variable types with serialization:

$array = $encrypter->decrypt($encrypted);

License

MIT license

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-26