简体   繁体   中英

Encrypting MP3 files in PHP and decrypting in JAVA

I basically want to encrypt the mp3 files uploaded by admins on the server (to be done in PHP). When my application downloads the file, i want it to decrypt and play it (To be done in JAVA).

What is the best encryption/decryption technique i can use and how to use it?

thank you.

Encryption/Decryption in PHP

 $key = "topSecretPassKey"; 
$crypted = encrypte($filecontents,$key);
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; 
  }

You should use some acceptable encrypt technique. You didn't mentioned any requirement for the encryption algorithm, so let us guess a little.

Simplest way is to use base64 encoding - it's implementation is easy and there should be no problem with it.

Other way is to use some enhanced encryption tools like pgp/gpg. You would need to set up your gpg tools and keys appropriately to encrypt/decrypt files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM