|
-
August 4th, 2007, 10:04 PM
#1
encrypt file in php
can anybody help me with encryption file..such as .avi .jpeg .mp3....
i know what to do..first i must convert those file to binary i think.can anybody suggest me an idea.
-
August 5th, 2007, 12:56 PM
#2
Re: encrypt file in php
Well, you could just read the contents and then encrypt them, then write them to the file.
PHP Code:
$file = 'path/to/file.txt';
$contents = file_get_contents($file);
if($contents){
// encrypt the $contents and write it to a file.
}
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
August 6th, 2007, 06:57 PM
#3
Re: encrypt file in php
 Originally Posted by PeejAvery
Well, you could just read the contents and then encrypt them, then write them to the file.
PHP Code:
$file = 'path/to/file.txt';
$contents = file_get_contents($file);
if($contents){
// encrypt the $contents and write it to a file.
}
well..actually i am pretty lost right now.can you give me a little bit of a direction..if i do something like below.i got an error.can i give a key to the encryption so that i can decrypt it back.
Warning: fopen(away-enlarge.jpg) [function.fopen]: failed to open stream: No such file or directory in D:\web\tesis\3.php on line 24
away-enlarge.jpg
$filename = $_FILES['file']['name'];
$handle = fopen($filename,'b');
$contents = file_get_contents($filename);
-
August 6th, 2007, 09:29 PM
#4
Re: encrypt file in php
Actually you need to check if the file awas correctly uploaded
Code:
if (is_uploaded_file($_FILES['file']['tmp_name'])) { //was the file uploaded?
$filecontents = gile_get_contents($_FILES['file']['tmp_name']);
unlink($_FILES['file']['tmp_name']); // delete the temp file
$key = "topSecretPassKey";
$crypted = encrypte($filecontents,$key);
// then do what you want with it
}
function GenerationCle($Texte,$CleDEncryptage)
{
$CleDEncryptage = md5($CleDEncryptage);
$Compteur=0;
$VariableTemp = "";
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++)
{
if ($Compteur==strlen($CleDEncryptage))
$Compteur=0;
$VariableTemp.= substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1);
$Compteur++;
}
return $VariableTemp;
}
function encrypt($Texte,$Cle)
{
srand((double)microtime()*1000000);
$CleDEncryptage = md5(rand(0,32000) );
$Compteur=0;
$VariableTemp = "";
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++)
{
if ($Compteur==strlen($CleDEncryptage))
$Compteur=0;
$VariableTemp.= substr($CleDEncryptage,$Compteur,1).(substr($Texte,$Ctr,1) ^ substr($CleDEncryptage,$Compteur,1) );
$Compteur++;
}
return base64_encode(GenerationCle($VariableTemp,$Cle) );
}
function decrypt($Texte,$Cle)
{
$Texte = GenerationCle(base64_decode($Texte),$Cle);
$VariableTemp = "";
for ($Ctr=0;$Ctr<strlen($Texte);$Ctr++)
{
$md5 = substr($Texte,$Ctr,1);
$Ctr++;
$VariableTemp.= (substr($Texte,$Ctr,1) ^ $md5);
}
return $VariableTemp;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|