项目作者: arthurkushman

项目描述 :
Coossions is a php plugin to store sessions in encrypted cookie
高级语言: PHP
项目地址: git://github.com/arthurkushman/coossions.git
创建时间: 2017-04-05T16:02:38Z
项目社区:https://github.com/arthurkushman/coossions

开源协议:MIT License

下载


coossions

Scrutinizer Code Quality
Build Status
Code Coverage
MIT Licence

Coossions (stands for cookie-sessions) is a php plugin to store sessions in encrypted cookie

Installation via composer

  1. composer require arthurkushman/coossions

Usage

  1. $coossions = new CoossionsHandler('your_digest_secrete'); // any secret word
  2. $coossions->startSession();

And then, as usual, in any code-space - set session global variables:

  1. $_SESSION['foo'] = 123;
  2. $_SESSION['bar'] = 'baz';

Get session global variables:

  1. echo $_SESSION['foo'] . ' ' . $_SESSION['bar'];

Details

Session will be written in cookie on client-side with openssl cipher code (in aes-256-ctr cipher algorithm by default)
and digested with your_digest_secrete (in sha256 by default).
Also, whole message will be merged with hash_hmac, based on salt consisting of dynamic SID + message,
which will then checked by hash_equals to additionally identify non-fraudulent data stored in cookie.

To create reliable/secure cryptographic signature, it would be better if your_digest_secrete will be in both upper/lower case letters and mashed with digits + long enough.

Setting custom hash and cryptographic algorithms through DI

Although, there are already set the best known, at the moment, hash and crypto algos - You can set Your preferable ones:

  1. $coossions = new CoossionsHandler('your_digest_secrete');
  2. $encryptor = new Encryptor('your_digest_secrete');
  3. $encryptor->setDigestAlgo('sha512'); // defaults to sha256
  4. $encryptor->setCipherAlgo('aes-128-ctr'); // defaults to aes-256-ctr
  5. $coossions->setEncryption($encryptor);
  6. $coossions->startSession();

Performance

Tested performance of write/read 2 $_SESSION vars (3 symbols long int/string):

  • write avg time 6-8 microseconds
  • read avg time 5-7 microseconds