daycry / encryption
Encryption for Codeigniter 4
Installs: 5 090
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
Requires (Dev)
README
Encryption Library
Encryption for Codeigniter 4 compatibility with CryptoJsAes
Installation via composer
Use the package with composer install
> composer require daycry/encryption
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
$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
$encryption = new \Daycry\Encryption\Encryption(); $data = $encryption->setCipher( 'AES-256-CTR' )->encrypt( 'data' ); var_dump( $data );
Setting Key
$encryption = new \Daycry\Encryption\Encryption(); $encrypt = $obj->setCipher( 'AES-256-CTR' )->setKey( '%T3sT1nG$' )->encrypt( 'data', true ); var_dump( $data );
Get algoritm available
var_dump( openssl_get_cipher_methods() );
CryptoJs Compatibility Returning Key
$result = \Daycry\Encryption\CryptoJsAes::encrypt( "Hello", "123456", true ); $textPlain = \Daycry\Encryption\CryptoJsAes::decrypt( $result );
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:
<script type="text/javascript" src="<?php echo base_url("assets/js/jquery.min.js")?>"></script> <script type="text/javascript" src="<?php echo base_url("assets/js/crypto-js.min.js")?>"></script> <script type="text/javascript" src="<?php echo base_url("assets/js/encryption.js")?>"></script> <script> Encryption.getInstance().setKey("hello"); var encrypted = Encryption.getInstance().encrypt("hello text"); var decrypted = Encryption.getInstance().decrypt(encrypted); console.log(decrypted); </script>
Encrypt and descrypt function accept the key as second parameter.
How Run Tests
cd vendor\daycry\encryption\ composer install vendor\bin\phpunit