Re: How to Looking at Raw Binary Data with PHP and curl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Is this good enough encryption for daily use ?

FYI, I need to keep the first part of the file unencrypted so the file will progressively load
Functions were taken from the mycrypt php page :)

$chunkSize = 32768;
$key = "6q9nKLg5"

   if( $fd  = fopen($filepath, 'rb')){

     while(!feof($fd)) {
		if($gotFastStartHeaders != true){
			echo fread($fd, $chunkSize/30);
			$gotFastStartHeaders = true;
		}else{
			echo encrypt(fread($fd, $chunkSize));
		}
 	}
     fclose ($fd);
     exit;
   }

/ /----------------------------------------------------------------------- -------------------
// Encrypt
function encrypt($encrypt) {
   global $key;
   //$key = "6q9nEUg5";
   srand((double) microtime() * 1000000); //for sake of MCRYPT_RAND
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $encrypt, MCRYPT_MODE_ECB, $iv);
   $encode = base64_encode($passcrypt);
 return $encode;
 }

/ /----------------------------------------------------------------------- -------------------
// Decrypt
 function decrypt($decrypt) {
   global $key;
   $decoded = base64_decode($decrypt);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_ECB, $iv);
 return $decrypted;

many thanks
g

On Sep 24, 2005, at 2:25 PM, Jasper Bryant-Greene wrote:

Graham Anderson wrote:
How do you display raw binary data of a file sent from a server with curl ?

You can probably just use file_get_contents() if allow_url_fopen is enabled (it is by default).

For binary data, base64_encode and it's friend base64_decode allow you to encode and decode binary data in a normal ASCII string.

http://php.net/file_get_contents
http://php.net/base64_encode

I want to encrypt the file with something akin to str_replace and decode it on the other side with a custom data handler Just want to make sure that I am str_replace'ing the actual data and not a representation of it :)

str_replace is not for encryption. You might want to look at mcrypt, as using str_replace is probably just as bad as sending the unencrypted string. It's not going to be secure.

http://php.net/mcrypt

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux