PHPackages                             daycry/encryption - 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. daycry/encryption

ActiveLibrary

daycry/encryption
=================

Encryption for Codeigniter 4

v2.1.8(1y ago)17.3k↓42.4%3MITPHPPHP ^8.1

Since Feb 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/daycry/encryption)[ Packagist](https://packagist.org/packages/daycry/encryption)[ RSS](/packages/daycry-encryption/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (17)Used By (3)

[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/donate?business=SYC5XDT23UZ5G&no_recurring=0&item_name=Thank+you%21&currency_code=EUR)

Encryption Library
==================

[](#encryption-library)

Encryption for Codeigniter 4 compatibility with CryptoJsAes

[![Build status](https://github.com/daycry/encryption/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/daycry/encryption/actions/workflows/main.yml)[![Coverage status](https://camo.githubusercontent.com/5b43efebc8349d4ff914a2296b17956280a786a32811775de1ca008a02ff53b8/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6461796372792f656e6372797074696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/daycry/encryption?branch=master)[![Downloads](https://camo.githubusercontent.com/66ecba4f046e2fcb1d1c830570a077ffbf65ed1162e0b0b3d6fcc61ee4dbd763/68747470733a2f2f706f7365722e707567782e6f72672f6461796372792f656e6372797074696f6e2f646f776e6c6f616473)](https://packagist.org/packages/daycry/encryption)[![GitHub release (latest by date)](https://camo.githubusercontent.com/8d6f594fcd8be1611e20a96af59d588ab81d85aae7868990905405ff14cdf07e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6461796372792f656e6372797074696f6e)](https://packagist.org/packages/daycry/encryption)[![GitHub stars](https://camo.githubusercontent.com/730fec6d0deb22c7f661d582a5e6a96441bac6aac8a7fd127b4367c9b1879173/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6461796372792f656e6372797074696f6e)](https://packagist.org/packages/daycry/encryption)[![GitHub license](https://camo.githubusercontent.com/3de5f553c23c003b05be2767b8c5aa289dd63cf06680af926349eb614d734f83/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6461796372792f656e6372797074696f6e)](https://github.com/daycry/encryption/blob/master/LICENSE)

Installation via composer
-------------------------

[](#installation-via-composer)

Use the package with composer install

```
> composer require daycry/encryption

```

Manual installation
-------------------

[](#manual-installation)

Download this repo and then enable it by editing **app/Config/Autoload.php** and adding the **Daycry\\Encryption**namespace to the **$psr4** array. For example, if you copied it into **app/ThirdParty**:

```
$psr4 = [
    'Config'      => APPPATH . 'Config',
    APP_NAMESPACE => APPPATH,
    'App'         => APPPATH,
    'Daycry\Encryption' => APPPATH .'Libraries/encryption/src',
];
```

Usage Loading Library
---------------------

[](#usage-loading-library)

```
$encryption = new \Daycry\Encryption\Encryption();
$data = $encryption->encrypt( 'data' );
var_dump( $data );

$encryption = new \Daycry\Encryption\Encryption();
$data = $encryption->decrypt( 'data' );
var_dump( $data );
```

Setting Cipher algoritm
-----------------------

[](#setting-cipher-algoritm)

```
$encryption = new \Daycry\Encryption\Encryption();
$data = $encryption->setCipher( 'AES-256-CTR' )->encrypt( 'data' );
var_dump( $data );
```

Setting Key
-----------

[](#setting-key)

```
$encryption = new \Daycry\Encryption\Encryption();
$encrypt = $obj->setCipher( 'AES-256-CTR' )->setKey( '%T3sT1nG$' )->encrypt( 'data', true );
var_dump( $data );
```

Get algoritm available
----------------------

[](#get-algoritm-available)

```
var_dump( openssl_get_cipher_methods() );
```

---

CryptoJs Compatibility Returning Key
------------------------------------

[](#cryptojs-compatibility-returning-key)

```
$result = \Daycry\Encryption\CryptoJsAes::encrypt( "Hello", "123456", true );

$textPlain = \Daycry\Encryption\CryptoJsAes::decrypt( $result );
```

CryptoJs Compatibility Without Returning Key
--------------------------------------------

[](#cryptojs-compatibility-without-returning-key)

```
$result = \Daycry\Encryption\CryptoJsAes::encrypt( "Hello", "123456", false );

$textPlain = \Daycry\Encryption\CryptoJsAes::decrypt( $result, "123456" );
```

If you want encrypt/decrypt in javascript you must add this files in your view.

```
./public/assets
```

Example:

```
