Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Example of ELC server encode. For MegaDownloader and MegaUploader - http://megadownloaderapp.blogspot.com/
- $key = "PutYourPasswordHere!!";
- // Your password, put some random data here. Once chosen, do not change it!!
- /*
- $_POST["USER"] = "test";
- $_POST["APIKEY"] = "test";
- $_POST["OPERATION_TYPE"] = "E";
- $_POST["DATA"] = "SHbWFsgPydjQL08l7BjtDubSqzClm4/1";
- $_POST["OPERATION_TYPE"] = "D";
- $_POST["DATA"] = "zLd5VbZvARy6s+Ml1a6gMgU/YDUQ7hoGJ9h0ip9nYgCos7vPKLp5YsHW7WoGXJ7k";
- */
- try {
- // Check user, password, etc. Do whatever you want.
- if ($_POST["USER"] != "test" or $_POST["APIKEY"] != "test"){
- throw new Exception('Invalid user or password');
- } else {
- // Decrypt or encrypt data
- if ($_POST["OPERATION_TYPE"] == "D") {
- die('{"e": "", "d": "'.decrypt($_POST["DATA"],$key).'"}');
- } else if ($_POST["OPERATION_TYPE"] == "E") {
- die('{"e": "", "d": "'.encrypt($_POST["DATA"],$key).'"}');
- } else {
- throw new Exception('Invalid input OPERATION_TYPE');
- }
- }
- } catch (Exception $e) {
- die('{"e": "'.$e->getMessage().'", "d": ""}');
- }
- // Encrypting AES-128
- function encrypt($string) {
- $enc = "";
- $iv = mcrypt_create_iv(mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc'),MCRYPT_DEV_URANDOM); // In Rijndael 128, the length will be always 16
- global $key;
- $enc = mcrypt_cbc (MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_ENCRYPT, $iv);
- $enc = $iv.$enc;
- return base64_encode($enc);
- }
- // Decrypting AES-128
- function decrypt($string) {
- $dec = "";
- $string = trim(base64_decode($string));
- if (strlen($string) < 17) { // check we have at least 16 chars (the IV!)
- throw new Exception('Invalid input DATA');
- }
- $iv = substr($string, 0, 16);
- $string = substr($string, 16);
- global $key;
- $dec = mcrypt_cbc (MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_DECRYPT, $iv);
- return $dec;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement