定制 openlss/lib-crypt 二次开发

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

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

openlss/lib-crypt

最新稳定版本:0.0.10

Composer 安装命令:

composer require openlss/lib-crypt

包简介

Shorthand library for using AES encryption provided by PHP-Mcrypt

README 文档

README

Shorthand library for using AES encryption provided by PHP-Mcrypt

Usage

use \LSS\Crypt;

//create keys
$iv_key = Crypt::IVCreate();
$crypt_key = Crypt::keyCreate();

$crypt = Crypt::_get($crypt_key,$iv_key);
$crypted_str = $crypt->encrypt('my string'); //returns base64 encoded crypted string
$var = $crypt->decrypt($crypted_str); //returns 'my string'

Padding

By default MCrypt will NULL-PAD strings to get the proper encryption. However this creates problems when expecting exact payload encryption (such as binary)

Crypt deals with this by storing the size of the payload as the first 4 bytes in the returned string Crypt then extracts this size and trims the payload to the original size upon decrypt

The downside to this is that it cant be decrypted by the regular MCrypt functions without first stripping the initial 4 bytes. It would be recommended to trim the payload if possible

Reference

(string) Crypt::IVCreate()

Returns a proper initialization vector for the encryption type

(string) Crypt::keyCreate()

Returns a proper secret key for the encryption type

(object) Crypt::_get($key,$iv)

Shorthand for the construct that returns the new object

(object) Crypt::setKey($key)

Change the key at runtime Returns $this so its chainable

(object) Crypt::setIV($iv)

Change the IV at runtime Returns $this so its chainable

(object) Crypt::verify()

Verifies the key and IV Will throw exceptions on errors Returns $this so its chainable

(string) Crypt::encrypt($plain_string,$base64_encode=true)

  • $plain_string String to be encrypted
  • $base64_encode TRUE to base64_encode the encrypted string Returns the encrypted and optionally base64_encoded string

(string) Crypt::decrypt($enc_string,$base64_decode=true)

  • $enc_string The encrypted string to be decrypted
  • $base64_decode If the $enc_string is base64_encoded set to TRUE Returns the EXACT original string

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2013-03-23