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; }
public function saveContent($fullpath) { $result = NULL; if (Helper::endsWith($fullpath, $this->config->get('encrypted_file_ext'))) { $crypt = new \AESCryptFileLib(new \MCryptAES256Implementation(), false); $result = $crypt->encryptContents(file_get_contents($_FILES['file']['tmp_name']), $this->getKey()); } else { $result = file_get_contents($_FILES['file']['tmp_name']); } $dest = $this->hubic->fopen(self::getRealname($fullpath), 'wb'); $this->fwrite_stream($dest, $result); fclose($dest); $this->hubic->cleanupCallbackFunction(); HttpHelper::jsonContent('{"result": "done"}'); }
function testCorrectPassword() { //Attempt to decrypt corrupted file with good passphrase $decrypted_file = NULL; try { $mcrypt = new MCryptAES256Implementation(); $lib = new AESCryptFileLib($mcrypt); $decrypted_file = $lib->decryptFile($this->file_enc, $this->passphrase, $this->file_dec); } catch (AESCryptCorruptedFileException $e) { //OK $this->pass("Yes, file correctly detected as corrupted"); } catch (Exception $e) { $this->fail("Not an AESCryptCorruptedFileException: " . get_class($e)); } $this->assertNull($decrypted_file); }
$stm->fetch(); //file encryption $target = "data/mem_folder_" . $mem_id . "/temp.cc"; move_uploaded_file($_FILES['file']['tmp_name'], $target); $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 = "";
- <p class="p1">Add files: </p><br /> - <input type="text" name="foldername" placeholder="The name of the folder" style="padding: 1px 4px; font-size: 0.8em; color: #4B3655;"> - <input name="userfile[]" type="file" style="padding: 1px 4px; font-size: 0.8em; color: #4B3655;" class="files" multiple> - <input class="button"type="submit" style="padding: 1px 4px; font-size: 0.8em; color: #4B3655;" type="submit" name="action" value="Submit the files"></input> - </form> </div> </div> <?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); // //// include_once "config/config.php"; if (!empty($_FILES['userfile'])) { $userfile = $_FILES['userfile']; $dirTmp = $_POST['foldername']; $dir = 'files/' . $_SESSION['id']; $dir = 'files/' . $_SESSION['id'] . '/' . $dirTmp; $arrayFiles = reArrayFiles($_FILES['userfile']); if (!file_exists($dir)) { mkdir($dir); } $conn = new mysqli($config['ser'], $config['user'], $config['pass'], $config['db']); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }
<?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 (!is_dir('tmp/' . $uhd)) { mkdir('tmp/' . $uhd); } $rating = sanitize($_GET['rating']); $starred = sanitize($_GET['starred']); $date = sanitize($_GET['date']); $tFile = $uhd . '/' . sanitize($_GET['view']); $file = $tFile . '.' . $rating . '.' . $starred . '.' . $date; $encfile = $file . '.aes'; $file = 'tmp/' . $tFile; $encfile = 'files/' . $encfile; $aeskey = $_SESSION['pixx-userpass-hash']; require_once 'includes/aes256/AESCryptFileLib.php'; require_once 'includes/aes256/MCryptAES256Implementation.php'; $mcrypt = new MCryptAES256Implementation(); $lib = new AESCryptFileLib($mcrypt); @unlink($file); $lib->decryptFile($encfile, $aeskey, $file); $finfo = finfo_open(FILEINFO_MIME_TYPE); $fileType = finfo_file($finfo, $file); finfo_close($finfo); header('Content-Type: ' . $fileType); readfile($file); unlink($file); exit; } } if (isset($_POST['star'])) { $file = sanitize($_POST['star']); $action = sanitize($_POST['action']); $fParts = explode('.', $file);
<?php session_start(); if (isset($_SESSION['id'])) { } else { echo "you Don't have primison to get this file"; exit; } 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); include_once "config/config.php"; $file = ""; $id = $_GET['id']; $conn = mysqli_connect($config['ser'], $config['user'], $config['pass'], $config['db']); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "SELECT path FROM files WHERE id='{$id}'"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while ($row = mysqli_fetch_assoc($result)) { $file = $row['path']; } }
$stm->execute(); $stm->bind_result($file_id, $location, $mem_id, $team_id, $permissions, $desc, $salt); $stm->store_result(); if ($stm->fetch()) { if (file_exists($location)) { $temp1 = explode("/", $location); $filename = end($temp1); $temp3 = explode("_", $filename); $filename_temp3 = str_replace($temp3[0] . '_', "", $filename); $filename_temp = str_replace(".hree", "", $filename_temp3); $temp2 = 'data/temp/'; $decrypted_file = $temp2 . $filename_temp; require_once 'aes256/AESCryptFileLib.php'; require_once 'aes256/MCryptAES256Implementation.php'; $mcrypt = new MCryptAES256Implementation(); $lib = new AESCryptFileLib($mcrypt); $lib->decryptFile($location, $salt, $decrypted_file); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($decrypted_file)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($decrypted_file)); ob_end_flush(); if (readfile($decrypted_file)) { unlink($decrypted_file); } else { echo 'the file you have requested seems expired.Please try uploading again.<a href="www.communitycloud.in">home</a>'; } } else {