PHPackages                             miserenkov/yii2-security - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. miserenkov/yii2-security

ActiveYii2-extension[Security](/categories/security)

miserenkov/yii2-security
========================

Yii2 extension for openssl encryption by public/private keys

1.0.1(6y ago)361[1 PRs](https://github.com/miserenkov/yii2-security/pulls)MITPHPPHP &gt;=5.6

Since Jan 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/miserenkov/yii2-security)[ Packagist](https://packagist.org/packages/miserenkov/yii2-security)[ RSS](/packages/miserenkov-yii2-security/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Yii2 Security extension
=======================

[](#yii2-security-extension)

Yii2 extension for encryption and decryption by openssl public/private keys

[![License](https://camo.githubusercontent.com/709301d802f49dad3373cd316ebf3d472545fd898dc07a12299fbbbfcdcd5232/68747470733a2f2f706f7365722e707567782e6f72672f6d69736572656e6b6f762f796969322d73656375726974792f6c6963656e7365)](https://packagist.org/packages/miserenkov/yii2-security)[![Latest Stable Version](https://camo.githubusercontent.com/9e7abf2549df8ca20ebf1f295b8844878e3a46e753e50faf207d749f5203d9ef/68747470733a2f2f706f7365722e707567782e6f72672f6d69736572656e6b6f762f796969322d73656375726974792f762f737461626c65)](https://packagist.org/packages/miserenkov/yii2-security)[![Latest Unstable Version](https://camo.githubusercontent.com/ac8d0b25f638b3c762387d0bedd19e13d1e0956a936dc023fd439e7215b1efb4/68747470733a2f2f706f7365722e707567782e6f72672f6d69736572656e6b6f762f796969322d73656375726974792f762f756e737461626c65)](https://packagist.org/packages/miserenkov/yii2-security)[![Total Downloads](https://camo.githubusercontent.com/c95ebbe7318ac270239b8fbc1a2a115b03c796f514e3e5cebd9e30ef292d3bf2/68747470733a2f2f706f7365722e707567782e6f72672f6d69736572656e6b6f762f796969322d73656375726974792f646f776e6c6f616473)](https://packagist.org/packages/miserenkov/yii2-security)[![Build Status](https://camo.githubusercontent.com/2236c5ed0636dd0f27868dea8969087fe07be769cea1cf5b6cc18d8c93be46b3/68747470733a2f2f7472617669732d63692e6f72672f6d69736572656e6b6f762f796969322d73656375726974792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/miserenkov/yii2-security)[![Dependency Status](https://camo.githubusercontent.com/f6c71d3923372af325982a2e85a9a22b8957960df4499ebc647b745e4f79ce7d/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3538373633353163396662373133303034393931313739382f62616467652e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/user/projects/5876351c9fb7130049911798)

Support
-------

[](#support)

[GitHub issues](https://github.com/miserenkov/yii2-security).

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist miserenkov/yii2-security "^1.0"

```

or add

```
"miserenkov/yii2-security": "^1.0"

```

to the require section of your `composer.json` file.

Configuration
-------------

[](#configuration)

To use security extension, you should configure it in the application configuration like the following

```
'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)
    ],
    ...
],
```

Basic usages
============

[](#basic-usages)

Encryption
----------

[](#encryption)

### Asymmetric encryption

[](#asymmetric-encryption)

Will return base64 encoded encrypted data.

###### With default public key

[](#with-default-public-key)

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

###### With custom public key

[](#with-custom-public-key)

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

### Hybrid encryption

[](#hybrid-encryption)

Will return array from encryption key and encrypted data (\['key' =&gt; '...', 'data' =&gt; '...'\]).

###### With default public key

[](#with-default-public-key-1)

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

###### With custom public key

[](#with-custom-public-key-1)

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

Decryption
----------

[](#decryption)

### Asymmetric decryption

[](#asymmetric-decryption)

Will return decrypted data.

###### With default private key

[](#with-default-private-key)

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

###### With custom private key

[](#with-custom-private-key)

```
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)
);
```

### Hybrid encryption

[](#hybrid-encryption-1)

Will return decrypted data.

###### With default private key

[](#with-default-private-key-1)

```
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
);
```

###### With custom private key

[](#with-custom-private-key-1)

```
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)
);
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1089 days

Total

2

Last Release

2366d ago

PHP version history (2 changes)v1.0PHP &gt;=5.5.0

1.0.1PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/2da4989419ba449f8a65c166d33be4472ab6a37d3e55092f17e8ac9eba5b3574?d=identicon)[miserenkov](/maintainers/miserenkov)

---

Top Contributors

[![miserenkov](https://avatars.githubusercontent.com/u/12072466?v=4)](https://github.com/miserenkov "miserenkov (13 commits)")

---

Tags

securityencryptdecryptopensslyii2privatepublickeys

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/miserenkov-yii2-security/health.svg)

```
[![Health](https://phpackages.com/badges/miserenkov-yii2-security/health.svg)](https://phpackages.com/packages/miserenkov-yii2-security)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k170.7M239](/packages/defuse-php-encryption)[nzo/url-encryptor-bundle

The NzoUrlEncryptorBundle is a Symfony Bundle used to Encrypt and Decrypt data and variables in the Web application or passed through URL

951.1M2](/packages/nzo-url-encryptor-bundle)[xxtea/xxtea

XXTEA is a fast and secure encryption algorithm. This is a XXTEA library for PHP.

11342.6k](/packages/xxtea-xxtea)[ionux/phactor

Phactor is a high-performance PHP implementation of the elliptic curve math functions required to generate &amp; verify private/public (asymmetric) EC keypairs and ECDSA signatures based on secp256k1 curve parameters. This library also includes a class to generate Service Identification Numbers (SINs) based on the published Identity Protocol v1 spec.

5283.3k30](/packages/ionux-phactor)[miladrahimi/phpcrypt

Encryption, decryption, and hashing tools for PHP projects

3074.2k2](/packages/miladrahimi-phpcrypt)[hemiframe/php-aes

PHP class for encrypt and decrypt data with AES algorithm

1031.0k](/packages/hemiframe-php-aes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
