Skip to content

Commit

Permalink
update Eccryption Library
Browse files Browse the repository at this point in the history
  • Loading branch information
ronmarasigan committed Jul 28, 2024
1 parent bc4bd7e commit 543805f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
11 changes: 11 additions & 0 deletions app/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@
$config['cache_dir'] = 'runtime/cache/';
$config['cache_default_expires'] = 0;

/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encryption class, you must set an encryption key.
|
|
*/
$config['encryption_key'] = '';

/*
|--------------------------------------------------------------------------
| Cross Site Request Forgery
Expand Down
5 changes: 0 additions & 5 deletions scheme/kernel/LavaLust.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ function _handlers()
*/
$lang =& load_class('lang', 'kernel');

/**
* Instantiate the encryption class
*/
$config =& load_class('encryption', 'kernel');

/**
* Load BaseController
*/
Expand Down
34 changes: 28 additions & 6 deletions scheme/kernel/Encryption.php → scheme/libraries/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,29 @@
* ------------------------------------------------------
*/
Class Encryption {

/**
* Encryption Key
*
* @var string
*/
private $encryption_key;

/**
* Cipher type
*
* @var string
*/
private $method;

public function __construct($method = '') {
if(empty(config_item('encryption_key')))
{
throw new RuntimeException('Encryption key is empty. Please provide the key in your config.php file.');
}
$this->encryption_key = config_item('encryption_key');
$this->method = empty($method) ? 'AES-256-CBC' : $method;
}
/**
* Encypt input value
*
Expand All @@ -49,11 +71,11 @@
* @param string $method
* @return void
*/
public function encrypt($input, $key, $method = 'AES-256-CBC')
public function encrypt($input)
{
$encrypt_iv = $this->_gen_encrypt_iv($key, openssl_cipher_iv_length($method));
$encrypt_iv = $this->_gen_encrypt_iv($this->encryption_key, openssl_cipher_iv_length($this->method));

return base64_encode(openssl_encrypt($input, $method, $key, 0, $encrypt_iv));
return base64_encode(openssl_encrypt($input, $this->method, $this->encryption_key, 0, $encrypt_iv));
}

/**
Expand All @@ -64,11 +86,11 @@ public function encrypt($input, $key, $method = 'AES-256-CBC')
* @param string $method
* @return void
*/
public function decrypt(string $input, string $key, string $method = 'AES-256-CBC')
public function decrypt($input)
{
$encrypt_iv = $this->_gen_encrypt_iv($key, openssl_cipher_iv_length($method));
$encrypt_iv = $this->_gen_encrypt_iv($this->encryption_key, openssl_cipher_iv_length($this->method));

return openssl_decrypt(base64_decode($input), $method, $key, 0, $encrypt_iv);
return openssl_decrypt(base64_decode($input), $this->method, $this->encryption_key, 0, $encrypt_iv);
}

/**
Expand Down

0 comments on commit 543805f

Please sign in to comment.