mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-07 10:08:27 +01:00
Fix: code more simple
This commit is contained in:
@@ -702,13 +702,19 @@ class DoliDb
|
||||
/**
|
||||
* \brief Encrypt sensitive data in database
|
||||
* \param fieldorvalue Field name or value to encrypt
|
||||
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
|
||||
* \param cryptKey Encryption key
|
||||
* \param withQuotes Return string with quotes
|
||||
* \return return XXX(field) or XXX('value') or field or 'value'
|
||||
*/
|
||||
function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0)
|
||||
function encrypt($fieldorvalue, $withQuotes=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
|
||||
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
|
||||
|
||||
//Encryption key
|
||||
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
|
||||
|
||||
$return = ($withQuotes?"'":"").addslashes($fieldorvalue).($withQuotes?"'":"");
|
||||
|
||||
if ($cryptType && !empty($cryptKey))
|
||||
@@ -728,24 +734,30 @@ class DoliDb
|
||||
|
||||
/**
|
||||
* \brief Decrypt sensitive data in database
|
||||
* \param field Field name to decrypt
|
||||
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
|
||||
* \param cryptKey Encryption key
|
||||
* \return return Field to decrypt if used
|
||||
* \param value Value to decrypt
|
||||
* \return return Decrypted value if used
|
||||
*/
|
||||
function decrypt($field, $cryptType=0, $cryptKey='')
|
||||
function decrypt($value)
|
||||
{
|
||||
$return = $field;
|
||||
global $conf;
|
||||
|
||||
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
|
||||
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
|
||||
|
||||
//Encryption key
|
||||
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
|
||||
|
||||
$return = $value;
|
||||
|
||||
if ($cryptType && !empty($cryptKey))
|
||||
{
|
||||
if ($cryptType == 2)
|
||||
{
|
||||
$return = 'AES_DECRYPT('.$field.',\''.$cryptKey.'\')';
|
||||
$return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')';
|
||||
}
|
||||
else if ($cryptType == 1)
|
||||
{
|
||||
$return = 'DES_DECRYPT('.$field.',\''.$cryptKey.'\')';
|
||||
$return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user