function encryptFileAndReturnLib() { $mcrypt = new MCryptAES256Implementation(); $lib = new AESCryptFileLib($mcrypt); //Encrypt file $encrypted_file = $lib->encryptFile($this->file_orig, $this->passphrase, $this->file_enc); $this->assertTrue(file_exists($encrypted_file)); $this->assertTrue(filesize($encrypted_file) > 0); return $lib; }
$time = microtime(true); $random_salt_temp = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true)); $time1 = microtime(true) - $time; echo $time1 * 1000000000; echo "<br/>"; $random_salt = hash('sha512', $mobile_no . $random_salt_temp); $time = microtime(true) - $time; echo $time * 1000000000; require_once 'aes256/AESCryptFileLib.php'; require_once 'aes256/MCryptAES256Implementation.php'; $mcrypt = new MCryptAES256Implementation(); $lib = new AESCryptFileLib($mcrypt); $file_to_encrypt = $_FILES["file"]["name"]; $encrypted_file = time() . "_" . $_FILES["file"]["name"] . ".hree"; $target1 = "data/mem_folder_" . $mem_id . "/" . $encrypted_file; if ($lib->encryptFile($target, $random_salt, $target1)) { if ($s3->putObjectFile($target1, $bucket, 'sa.png', S3::ACL_PUBLIC_READ)) { echo 32; } unlink($target); //@unlink($decrypted_file); // //$lib->decryptFile($encrypted_file, $random_salt, $decrypted_file); $team_select = 0; $desc_u = $team_u = ''; $desc_u = $_POST['text_desc']; $team_u = $_POST['share_select']; $permissions_u = $team_p = ""; if ($team_u) { if (strlen(strpos($team_u, "m_s_")) > 0) { $team_u = str_replace("m_s_", "", $team_u); $team_p = $team_u;
$csql = "SELECT* FROM files WHERE path = '{$spath}')"; $result = mysqli_query($conn, $csql); if (!$result) { //VALUES ('$file', '$spath', md5('$spath'))"; $sql = "INSERT INTO files (name, path, id) \n\t\t\t\t VALUES ('{$file}', '{$spath}', '{$idd}')"; if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } else { mysqli_free_result($result); } if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $dir . '/' . $file)) { @unlink($dir . '/' . $file . 'aes'); $lib->encryptFile($dir . '/' . $file, $_SESSION['id'], $dir . '/' . $file . '.aes'); @unlink($dir . '/' . $file); echo 'File uploaded :' . $file . '<br/>'; } else { echo 'Error!' . '<br/>' . 'max upload size is 200 MB'; } if ($i >= count($arrayFiles)) { break; } } } function reArrayFiles(&$file_post) { $file_ary = array(); $file_count = count($file_post['name']); $file_keys = array_keys($file_post);
<?php // Include the library require_once 'AESCryptFileLib.php'; // Include an AES256 Implementation require_once 'aes256/MCryptAES256Implementation.php'; // Construct the implementation $mcrypt = new MCryptAES256Implementation(); // Use this to instantiate the encryption library class $lib = new AESCryptFileLib($mcrypt); // This example encrypts and decrypts the README.md file $file_to_encrypt = "README.md"; $encrypted_file = "README.md.aes"; $decrypted_file = "README.decrypted.txt"; // Ensure target file does not exist @unlink($encrypted_file); // Encrypt a file $lib->encryptFile($file_to_encrypt, "1234", $encrypted_file); // Ensure file does not exist @unlink($decrypted_file); // Decrypt using same password $lib->decryptFile($encrypted_file, "1234", $decrypted_file); echo "Done";
if (move_uploaded_file($tFile, $targetPath)) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $fileType = finfo_file($finfo, $targetPath); finfo_close($finfo); require_once 'includes/aes256/AESCryptFileLib.php'; require_once 'includes/aes256/MCryptAES256Implementation.php'; $mcrypt = new MCryptAES256Implementation(); $lib = new AESCryptFileLib($mcrypt); if (preg_match("/image/i", $fileType)) { include 'includes/ImageResize.php'; $image = new \Eventviva\ImageResize($targetPath); $image->resizeToWidth(180)->save($thumbnailPath); $file_enc = $fName . '.aes'; $thumb_enc = $thumbName . '.aes'; @unlink($path . '/' . $file_enc); $lib->encryptFile($targetPath, $aeskey, $path . '/' . $file_enc); @unlink($path . '/thumbnails/' . $file_enc); $lib->encryptFile($thumbnailPath, $aeskey, $path . '/thumbnails/' . $thumb_enc); @unlink($targetPath); @unlink($thumbnailPath); } else { if (preg_match("/video/i", $fileType)) { $file_enc = $fName . '.aes'; //$thumb_enc = $thumbName.'.aes'; @unlink($path . '/' . $file_enc); $lib->encryptFile($targetPath, $aeskey, $path . '/' . $file_enc); //@unlink($path.'/thumbnails/'.$file_enc); //$lib->encryptFile($thumbnailPath, $aeskey, $path.'/thumbnails/'.$thumb_enc); @unlink($targetPath); //@unlink($thumbnailPath); }