1
0
Fork 0
template/functions/endecrypt.php

37 lines
972 B
PHP
Raw Normal View History

2024-04-25 21:55:08 +02:00
<?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 {
2024-11-16 12:37:44 +01:00
return Symmetric::decrypt($string, $enckey)->getString();
2024-04-25 21:55:08 +02:00
}
} else {
if($encrypt == true) {
File::encrypt($string, $string.'.enc', $enckey);
} else {
File::decrypt($string.'.enc', $string, $enckey);
}
}
}
}
2024-09-23 20:40:19 +02:00
?>