1
0
Fork 0
template/functions/endecrypt.php
2024-04-25 21:55:08 +02:00

37 lines
960 B
PHP
Executable file

<?php
use ParagonIE\Halite\File;
use ParagonIE\Halite\KeyFactory;
use ParagonIE\Halite\Symmetric\Crypto as Symmetric;
use ParagonIE\HiddenString\HiddenString;
set_time_limit(300);
function endecrypt($string, $encrypt = true, $file = false) {
global $dir_files, $site_url;
if(!file_exists($dir_files.'/'.hash('sha256', $site_url).'.key')) {
$enckey = KeyFactory::generateEncryptionKey();
KeyFactory::save($enckey, $dir_files.'/'.hash('sha256', $site_url).'.key');
} else {
$enckey = KeyFactory::loadEncryptionKey($dir_files.'/'.hash('sha256', $site_url).'.key');
if($file == false) {
if($encrypt == true) {
return Symmetric::encrypt(new HiddenString($string), $enckey);
} else {
return Symmetric::decrypt($string, $enckey);
}
} else {
if($encrypt == true) {
File::encrypt($string, $string.'.enc', $enckey);
} else {
File::decrypt($string.'.enc', $string, $enckey);
}
}
}
}
?>