PHP code example of miserenkov / yii2-security

1. Go to this page and download the library: Download miserenkov/yii2-security library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

miserenkov / yii2-security example snippets


'components' => [
    ...
    'security' => [
        'class' => 'miserenkov\security\Security',
        
        'certificateFile' => '',    // alias or path to default certificate file
        // or
        'publicKeyFile' => '',      // alias or path to default public key file
        
        'privateKeyFile' => '',     // alias or path to default private key file
        'passphrase' => '',         // passphrase to default private key (if exists)
    ],
    ...
],

Yii::$app->security->encryptByPublicKey(
    $data           // string data for ecnryption
);

Yii::$app->security->encryptByPublicKey(
    $data,          // string data for ecnryption
    $publicKey      // alias or path to custom public key or PEM formatted public key
);

Yii::$app->security->encryptHybrid(
    $data           // string data for ecnryption
);

Yii::$app->security->encryptHybrid(
    $data,          // string data for ecnryption
    $publicKey      // alias or path to custom public key or PEM formatted public key
);

Yii::$app->security->decryptByPrivateKey(
    $data           // string data for decryption
);

Yii::$app->security->decryptByPrivateKey(
    $data,          // string data for decryption
    $privateKey,    // alias or path to custom private key or PEM formatted private key
    $passphrase     // passphrase for private key (if exists)
);

Yii::$app->security->decryptHybrid(
    $data,          // string data for decryption or array from 
                    // encryption key and ecnrypted data (['key' => '...', 'data' => '...'])
    $key            // encryption key if $data as string
);

Yii::$app->security->decryptHybrid(
    $data,          //string data for decryption or array from 
                    // encryption key and ecnrypted data (['key' => '...', 'data' => '...'])
    $key,           // encryption key if $data as string
    $privateKey,    // alias or path to custom private key or PEM formatted private key
    $passphrase     // passphrase for private key (if exists)
);

php composer.phar