Files
starter_template_ci_adminlte/application/helpers/security_helper.php
2024-01-08 09:33:24 +07:00

36 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php if (!defined("BASEPATH")) exit("No direct script access allowed");
function encrypt_url($string) {
$output = false;
/*
* read security.ini file & get encryption_key | iv | encryption_mechanism value for generating encryption code
*/
$security = parse_ini_file("security.ini");
$secret_key = $security["encryption_key"];
$secret_iv = $security["iv"];
$encrypt_method = $security["encryption_mechanism"];
// hash
$key = hash("sha256", $secret_key);
// iv encrypt method AES-256-CBC expects 16 bytes else you will get a warning
$iv = substr(hash("sha256", $secret_iv), 0, 16);
//do the encryption given text/string/number
$result = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$output = base64_encode($result);
return $output;
}
function decrypt_url($string) {
$output = false;
/*
* read security.ini file & get encryption_key | iv | encryption_mechanism value for generating encryption code
*/
$security = parse_ini_file("security.ini");
$secret_key = $security["encryption_key"];
$secret_iv = $security["iv"];
$encrypt_method = $security["encryption_mechanism"];
// hash
$key = hash("sha256", $secret_key);
// iv encrypt method AES-256-CBC expects 16 bytes else you will get a warning
$iv = substr(hash("sha256", $secret_iv), 0, 16);
//do the decryption given text/string/number
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
return $output;
}