SHARE
TWEET

ELC example - MegaDownloader

a guest Mar 28th, 2013 1,561 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Example of ELC server encode. For MegaDownloader and MegaUploader - http://megadownloaderapp.blogspot.com/
  3.  
  4.  
  5. $key = "PutYourPasswordHere!!";
  6. // Your password, put some random data here. Once chosen, do not change it!!
  7.  
  8. /*
  9. $_POST["USER"] = "test";
  10. $_POST["APIKEY"] = "test";
  11. $_POST["OPERATION_TYPE"] = "E";
  12. $_POST["DATA"] = "SHbWFsgPydjQL08l7BjtDubSqzClm4/1";
  13. $_POST["OPERATION_TYPE"] = "D";
  14. $_POST["DATA"] = "zLd5VbZvARy6s+Ml1a6gMgU/YDUQ7hoGJ9h0ip9nYgCos7vPKLp5YsHW7WoGXJ7k";
  15. */
  16.  
  17. try {
  18.  
  19.   // Check user, password, etc. Do whatever you want.
  20.   if ($_POST["USER"] != "test" or $_POST["APIKEY"] != "test"){
  21.  
  22.     throw new Exception('Invalid user or password');
  23.  
  24.   } else {
  25.  
  26.     // Decrypt or encrypt data
  27.     if ($_POST["OPERATION_TYPE"] == "D") {
  28.        die('{"e": "", "d": "'.decrypt($_POST["DATA"],$key).'"}');
  29.     } else if ($_POST["OPERATION_TYPE"] == "E") {
  30.        die('{"e": "", "d": "'.encrypt($_POST["DATA"],$key).'"}');
  31.     } else {
  32.        throw new Exception('Invalid input OPERATION_TYPE');
  33.     }
  34.  
  35.   }
  36.  
  37. } catch (Exception $e) {
  38.  
  39.  die('{"e": "'.$e->getMessage().'", "d": ""}');
  40.  
  41. }
  42.  
  43.  
  44.  
  45. // Encrypting AES-128
  46. function encrypt($string) {
  47.     $enc = "";
  48.     $iv = mcrypt_create_iv(mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc'),MCRYPT_DEV_URANDOM); // In Rijndael 128, the length will be always 16
  49.     global $key;
  50.     $enc = mcrypt_cbc (MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_ENCRYPT, $iv);
  51.     $enc = $iv.$enc;
  52.  
  53.   return base64_encode($enc);
  54. }
  55.  
  56. // Decrypting AES-128
  57. function decrypt($string) {
  58.     $dec = "";
  59.     $string = trim(base64_decode($string));
  60.     if (strlen($string) < 17) { // check we have at least 16 chars (the IV!)
  61.         throw new Exception('Invalid input DATA');
  62.     }
  63.     $iv = substr($string, 0, 16);
  64.     $string = substr($string, 16);
  65.     global $key;
  66.     $dec = mcrypt_cbc (MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_DECRYPT, $iv);
  67.   return $dec;
  68. }
  69.  
  70.  ?>
RAW Paste Data
Want to get better at PHP?
Learn to code PHP in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top