3declare(strict_types=1);
27 static private string $db_key =
"";
29 static private string $default_openssl_method =
"";
31 static private string $default_openssl_iv =
"";
33 static private string $default_openssl_ivlen =
"";
35 static private int $default_openssl_options = 0;
43 protected function cryptString(
string $sSource=
""): string|bool
45 if(
"" === self::$default_openssl_method )
47 echo
LEPTON_tools::display(
"UNABLE to crypt source! Keep source untouched.",
"pre",
"ui message red");
50 return openssl_encrypt(
52 self::$default_openssl_method,
54 self::$default_openssl_options,
55 self::$default_openssl_iv
66 if ((
"" === self::$default_openssl_method) || (
"" === $sSource))
71 return openssl_decrypt(
73 self::$default_openssl_method,
75 self::$default_openssl_options,
76 self::$default_openssl_iv
92 self::$default_openssl_method = $sMethodName;
102 self::$default_openssl_iv = $sNewIV;
120 $result = $this->get_one($SQL);
121 return (is_null($result))
152 bool $bFetch =
false,
153 array &$aStorage = array(),
154 bool $bFetchAll =
true,
155 array $aListOfFields = array()
158 if (!is_array($aListOfFields))
164 $result = $this->execute_query(
171 if (
false === $result)
177 if (
true === $bFetchAll)
179 foreach ($aStorage as &$ref)
181 foreach ($aListOfFields as $sFieldname)
183 if (isset($ref[$sFieldname]))
185 $ref[$sFieldname] = $this->
decryptString( (
string)$ref[$sFieldname]);
190 foreach ($aListOfFields as $sFieldname)
192 if (isset($aStorage[$sFieldname]))
194 $aStorage[$sFieldname] = $this->
decryptString( (
string)$aStorage[$sFieldname]);
220 array $table_values = [] ,
221 string $condition =
"",
222 array $aListOfFields = [],
227 if (!is_array($aListOfFields))
233 foreach ($aListOfFields as $sName)
235 if (isset($table_values[$sName]))
237 $table_values[ $sName ] = $this->
cryptString( (
string)$table_values[$sName]);
241 return $this->build_and_execute(
263 public static function __callStatic($method, $args)
265 switch (strtolower($method))
268 return self::$instance->cryptString((
string)$args[0]);
271 case 'decryptstring':
272 return self::$instance->decryptString((
string)$args[0]);
setOpenSSLIv(string $sNewIV)
secure_execute_query(string $aQuery="", bool $bFetch=false, array &$aStorage=array(), bool $bFetchAll=true, array $aListOfFields=array())
cryptString(string $sSource="")
secure_build_and_execute(string $type, string $table_name, array $table_values=[], string $condition="", array $aListOfFields=[], string $key="")
trait LEPTON_secure_database
secure_get_one(string $SQL)
decryptString(string $sSource)
setOpenSSLMethod(string $sMethodName)