dovechen/yii2-aes

Yii2 AES Encrypt&&Decrypt

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:yii2-extension

V1.0.0 2020-03-25 06:28 UTC

This package is auto-updated.

Last update: 2020-05-25 06:52:06 UTC


README

Yii2 AES Encrypt && Decrypt

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist dovechen/yii2-aes "*"

or add

"dovechen/yii2-aes": "*"

to the require section of your composer.json file.

Usage

Aes init

'components' => [
    ...
    'aes' => [
        'class' => 'dovechen\yii2\aes\Aes',
        'key'   => 'Y34lM1IyOSUTEa5h', // The encrypt & decrypt key.
        'iv'    => 'jKWFi17PZhpy08In', // A non-NULL Initialization Vector, default: 397e2eb61307109f.
    ]
  ...
]
// Global Use
$aesMcrypt = Yii::$app->aes; 


// More Use
$aesMcrypt = Yii::createObject([
    'class' => 'dovechen\yii2\aes\Aes',
    'key'   => 'Y34lM1IyOSUTEa5h', // The encrypt & decrypt key.
    'iv'    => 'jKWFi17PZhpy08In', // A non-NULL Initialization Vector, default: 397e2eb61307109f.
]);

Example:

$content = "hello world";

echo '<pre>' . PHP_EOL;
echo 'mcrypt 加密:' . PHP_EOL;
$aesMcrypt = Yii::$app->aes;
var_dump($data = Yii::$app->aes->encrypt($content));
echo 'mcrypt 解密:' . PHP_EOL;
var_dump(Yii::$app->aes->decrypt($data));
echo '</pre>'. PHP_EOL;