Cryptage SMTP

This commit is contained in:
Fred Tempez 2023-03-27 11:34:22 +02:00
parent 53b78bf61d
commit 0cd7a54904
3 changed files with 25 additions and 3 deletions

View File

@ -682,4 +682,26 @@ class helper
return $text; return $text;
} }
/**
* Cryptage
* @param string $key la clé d'encryptage
* @param string $string la chaine à coder
* @return string
*/
public static function encrypt($string, $key) {
$encrypted = openssl_encrypt($string, "AES-256-CBC", $key, 0, substr(md5($key), 0, 16));
return base64_encode($encrypted);
}
/**
* Décryptage
* @param string $key la clé d'encryptage
* @param string $string la chaine à décoder
* @return string
*/
public static function decrypt($string, $key) {
$decrypted = openssl_decrypt(base64_decode($string), "AES-256-CBC", $key, 0, substr(md5($key), 0, 16));
return $decrypted;
}
} }

View File

@ -1149,7 +1149,7 @@ class common
$mail->SMTPSecure = true; $mail->SMTPSecure = true;
$mail->SMTPAuth = $this->getData(['config', 'smtp', 'auth']); $mail->SMTPAuth = $this->getData(['config', 'smtp', 'auth']);
$mail->Username = $this->getData(['config', 'smtp', 'username']); $mail->Username = $this->getData(['config', 'smtp', 'username']);
$mail->Password = $this->getData(['config', 'smtp', 'password']); $mail->Password = helper::decrypt($this->getData(['config', 'smtp', 'password']),$this->getData(['config', 'smtp', 'host']));
} }
} }
@ -1183,7 +1183,7 @@ class common
return $mail->ErrorInfo; return $mail->ErrorInfo;
} }
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $mail->ErrorInfo;
} }
} }

View File

@ -460,7 +460,7 @@ class config extends common
'auth' => $this->getInput('smtpAuth', helper::FILTER_BOOLEAN), 'auth' => $this->getInput('smtpAuth', helper::FILTER_BOOLEAN),
'secure' => $this->getInput('smtpSecure', helper::FILTER_STRING_SHORT), 'secure' => $this->getInput('smtpSecure', helper::FILTER_STRING_SHORT),
'username' => $this->getInput('smtpUsername', helper::FILTER_STRING_SHORT), 'username' => $this->getInput('smtpUsername', helper::FILTER_STRING_SHORT),
'password' => $this->getInput('smtpPassword', helper::FILTER_STRING_SHORT), 'password' => helper::encrypt($this->getInput('smtpPassword', helper::FILTER_STRING_SHORT),$this->getInput('smtpHost', helper::FILTER_STRING_SHORT)),
'from' => $this->getInput('smtpFrom', helper::FILTER_MAIL, true), 'from' => $this->getInput('smtpFrom', helper::FILTER_MAIL, true),
], ],
'seo' => [ 'seo' => [