Commit 3991dd24 authored by Regis's avatar Regis
Browse files

Merge branch '78_map_image_security_and_encryption' into 'master'

78 map image security and encryption

See merge request a_boiteau/site-vikazimut-stage!40
parents 5f37df31 acf81f0a
......@@ -142,6 +142,7 @@ class DataController extends AbstractController
return $response;
}
/**
* @Route("/data/{id}/img", name="img")
*/
......@@ -173,98 +174,6 @@ class DataController extends AbstractController
return $response;
}
*/
/**
* @Route("/data/{id}/img", name="img")
*/
/* public function get_image_encrypted_archive($id): Response TODO version zip
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
return $this->json(["error" => "invalid id"]);
}
$zip = new ZipArchive;
$zip->open($id.".zip", ZipArchive::CREATE);
$zip->setPassword('test');
$zip->addFile($course->getImage(), $id.".jpeg");
$zip->setEncryptionName($id.".jpeg", ZipArchive::EM_TRAD_PKWARE);
$zip->close();
$response = new Response(file_get_contents($id.".zip"));
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$id."."."zip"
);
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'application/zip');
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Length', filesize($id.".zip"));
return $response;
}*/
function encryptFile($encKey, $encIV, $inPath, $outPath): int
{
$sourceFile = file_get_contents($inPath);
$key = base64_decode($encKey);
$iv = base64_decode($encIV);
$path_parts = pathinfo($inPath);
$fileName = $path_parts['filename'];
$outFile = $outPath.$fileName.'.himu';
$encrypter = 'aes-256-cbc';
$encryptedString = openssl_encrypt($sourceFile, $encrypter, $key, 0, $iv);
if (file_put_contents($outFile, $encryptedString) != false) {
return 1;
} else {
return 0;
}
}
// kept for future use.
function decryptFile($encKey, $encIV, $inPath, $outPath): int
{
$encryptedString=file_get_contents($inPath);
$key = base64_decode($encKey);
$iv = base64_decode($encIV);
$path_parts = pathinfo($inPath);
$fileName=$path_parts['filename'];
$outFile=$outPath.$fileName.'.jpoeg';
$encrypter = 'aes-256-cbc';
$decrypted = openssl_decrypt($encryptedString, $encrypter, $key, 0, $iv);
if(file_put_contents($outFile, $decrypted)!= false) return 1;
else return 0;
}
/**
* @Route("/data/{id}/img", name="img")
*/
public function get_image_encrypted_archive($id): Response
{
$course = $this->getDoctrine()->getRepository(Course::class)->find($id);
if (!$course) {
return $this->json(["error" => "invalid id"]);
}
$key = 'FCAcEA0HBAoRGyALBQIeCAcaDxYWEQQPBxcXHgAFDgY=';
$iv = 'DB4gHxkcBQkKCxoRGBkaFA==';
$this->encryptFile($key, $iv, $course->getImage(), "");
/* $zip = new ZipArchive;
$zip->open($id.".zip", ZipArchive::CREATE);
$zip->setPassword('test');
$zip->addFile($course->getImage(), $id.".jpeg");
$zip->setEncryptionName($id.".jpeg", ZipArchive::EM_TRAD_PKWARE);
$zip->close();*/
$response = new Response(file_get_contents($id.".himu"));
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $id.".himu");
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'application/octet-stream');
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Length', filesize($id.".himu"));
return $response;
}
/**
* @Route("/data/{id}/kml", name="kml")
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment