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;
40 private bool $bOpenSslInstalled =
false;
47 protected function cryptString(
string $sSource=
""): string|bool
49 if(
false === $this->bOpenSslInstalled )
53 return openssl_encrypt(
55 self::$default_openssl_method,
57 self::$default_openssl_options,
58 self::$default_openssl_iv
69 if ((
false === $this->bOpenSslInstalled) || (
"" === $sSource))
74 return openssl_decrypt(
76 self::$default_openssl_method,
78 self::$default_openssl_options,
79 self::$default_openssl_iv
95 self::$default_openssl_method = $sMethodName;
105 self::$default_openssl_iv = $sNewIV;
123 $result = $this->get_one($SQL);
124 return (is_null($result))
155 bool $bFetch =
false,
156 array &$aStorage = array(),
157 bool $bFetchAll =
true,
158 array $aListOfFields = array()
161 if (!is_array($aListOfFields))
167 $result = $this->execute_query(
174 if (
false === $result)
180 if (
true === $bFetchAll)
182 foreach ($aStorage as &$ref)
184 foreach ($aListOfFields as $sFieldname)
186 if (isset($ref[$sFieldname]))
188 $ref[$sFieldname] = $this->
decryptString( (
string)$ref[$sFieldname]);
193 foreach ($aListOfFields as $sFieldname)
195 if (isset($aStorage[$sFieldname]))
197 $aStorage[$sFieldname] = $this->
decryptString( (
string)$aStorage[$sFieldname]);
223 array $table_values = [] ,
224 string $condition =
"",
225 array $aListOfFields = [],
226 bool $display_query =
false
230 if (!is_array($aListOfFields))
236 foreach ($aListOfFields as $sName)
238 if (isset($table_values[$sName]))
240 $table_values[ $sName ] = $this->
cryptString( (
string)$table_values[$sName]);
244 return $this->build_and_execute(
266 public static function __callStatic($method, $args)
268 switch (strtolower($method))
271 return self::$instance->cryptString((
string)$args[0]);
274 case 'decryptstring':
275 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="")
trait LEPTON_secure_database
secure_get_one(string $SQL)
decryptString(string $sSource)
setOpenSSLMethod(string $sMethodName)
secure_build_and_execute(string $type, string $table_name, array $table_values=[], string $condition="", array $aListOfFields=[], bool $display_query=false)