mirror of
https://github.com/24eme/signaturepdf
synced 2024-05-21 07:06:41 +02:00
Outsourcing of the cryptography functions
This commit is contained in:
parent
aa951558fb
commit
579379318f
40
app.php
40
app.php
|
@ -190,6 +190,8 @@ $f3->route('POST /sign',
|
|||
}
|
||||
);
|
||||
|
||||
require_once 'lib/cryptography.class.php';
|
||||
|
||||
$f3->route('POST /share',
|
||||
function($f3) {
|
||||
$hash = substr(hash('sha512', uniqid().rand()), 0, 20);
|
||||
|
@ -237,17 +239,9 @@ $f3->route('POST /share',
|
|||
if(!$f3->get('DEBUG')) {
|
||||
array_map('unlink', glob($tmpfile."*.svg"));
|
||||
}
|
||||
$key = "test";
|
||||
foreach (glob("/tmp/".$hash.'/*.pdf') as $file) {
|
||||
$outputFile = $file.".gpg";
|
||||
$command = "echo '$key' | gpg --batch --passphrase-fd 0 --symmetric --cipher-algo AES256 -o $outputFile $file";
|
||||
$result = shell_exec($command);
|
||||
if ($result === false) {
|
||||
echo "Cypher failure.";
|
||||
exit;
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
$encryptor = new CryptographyClass();
|
||||
$encryptor->encrypt($hash);
|
||||
$f3->reroute($f3->get('REVERSE_PROXY_URL').'/signature/'.$hash."#informations");
|
||||
}
|
||||
|
||||
|
@ -259,17 +253,8 @@ $f3->route('GET /signature/@hash/pdf',
|
|||
$hash = Web::instance()->slug($f3->get('PARAMS.hash'));
|
||||
$sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash;
|
||||
|
||||
$key = "test";
|
||||
foreach (glob("/tmp/".$hash.'/*.gpg') as $file) {
|
||||
$outputFile = str_replace(".gpg", "", $file);
|
||||
$command = "echo '$key' | gpg --batch --passphrase-fd 0 --decrypt -o $outputFile $file";
|
||||
$result = shell_exec($command);
|
||||
if ($result === false) {
|
||||
echo "Decypher failure.";
|
||||
exit;
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
$cryptor = new CryptographyClass();
|
||||
$cryptor->decrypt($hash);
|
||||
|
||||
$files = scandir($sharingFolder);
|
||||
$originalFile = $sharingFolder.'/original.pdf';
|
||||
|
@ -296,16 +281,7 @@ $f3->route('GET /signature/@hash/pdf',
|
|||
}
|
||||
Web::instance()->send($finalFile, null, 0, TRUE, $filename);
|
||||
|
||||
foreach (glob("/tmp/".$hash.'/*.pdf') as $file) {
|
||||
$outputFile = $file.".gpg";
|
||||
$command = "echo '$key' | gpg --batch --passphrase-fd 0 --symmetric --cipher-algo AES256 -o $outputFile $file";
|
||||
$result = shell_exec($command);
|
||||
if ($result === false) {
|
||||
echo "Cypher failure.";
|
||||
exit;
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
$cryptor->encrypt($hash);
|
||||
|
||||
if($f3->get('DEBUG')) {
|
||||
return;
|
||||
|
|
34
lib/cryptography.class.php
Normal file
34
lib/cryptography.class.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
class CryptographyClass
|
||||
{
|
||||
public function encrypt($hash) {
|
||||
$key = "test";
|
||||
foreach (glob("/tmp/".$hash.'/*.pdf') as $file) {
|
||||
$outputFile = $file.".gpg";
|
||||
$command = "echo '$key' | gpg --batch --passphrase-fd 0 --symmetric --cipher-algo AES256 -o $outputFile $file";
|
||||
$result = shell_exec($command);
|
||||
if ($result === false) {
|
||||
echo "Cypher failure";
|
||||
exit;
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt($hash) {
|
||||
$key = "test";
|
||||
foreach (glob("/tmp/".$hash.'/*.gpg') as $file) {
|
||||
$outputFile = str_replace(".gpg", "", $file);
|
||||
$command = "echo '$key' | gpg --batch --passphrase-fd 0 --decrypt -o $outputFile $file";
|
||||
$result = shell_exec($command);
|
||||
if ($result === false) {
|
||||
echo "Decypher failure";
|
||||
exit;
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue