Better error handling for crypt_data and also better password argument handling

This commit is contained in:
jim-p 2012-04-30 10:07:29 -04:00
parent 3f76f90e65
commit 15855fbc5b

View File

@ -35,11 +35,16 @@
function crypt_data($val, $pass, $opt) {
$file = tempnam("/tmp", "php-encrypt");
file_put_contents("{$file}.dec", $val);
exec("/usr/bin/openssl enc {$opt} -aes-256-cbc -in {$file}.dec -out {$file}.enc -k {$pass}");
$result = file_get_contents("{$file}.enc");
unlink($file);
unlink("{$file}.dec");
unlink("{$file}.enc");
exec("/usr/bin/openssl enc {$opt} -aes-256-cbc -in {$file}.dec -out {$file}.enc -k " . escapeshellarg($pass));
if (file_exists("{$file}.enc"))
$result = file_get_contents("{$file}.enc");
else {
$result = "";
log_error("Failed to encrypt/decrypt data!");
}
@unlink($file);
@unlink("{$file}.dec");
@unlink("{$file}.enc");
return $result;
}