1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
<?php
class CryptPDF
{
private $pdfOriginal = '';
private $pdfCrypt ='';
private $key;
private $iv;
public function __construct($key,$filein,$fileout=null)
{
$this->pdfOriginal = $filein;
$this->pdfCrypt = $fileout;
$key_size = mcrypt_module_get_algo_key_size(MCRYPT_3DES);
$this->key = substr($this->key, 0, $key_size);
$iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_NOFB);
$this->iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
}
public function crypt()
{
$data2Crypt = $this->readFile();
$dataCrypted = mcrypt_encrypt(MCRYPT_3DES, $this->key, $data2Crypt, MCRYPT_MODE_NOFB, $this->iv);
$this->writeFile($dataCrypted);
}
private function readFile()
{
$handle = fopen($this->pdfOriginal,'r');
$data = fread($handle, filesize($this->pdfOriginal));
fclose($handle);
return $data;
}
private function writeFile($data)
{
$handle = fopen($this->pdfCrypt,'w');
$data = fwrite($handle, $data);
fclose($handle);
}
}
$crypt = new CryptPDF('qsdo4sdkflSDLKFD','mon.pdf','mon.pdf.crypt');
$crypt->crypt(); |
Partager