-
-
Save Stricted/f541b7cb2e79d0242091 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define("AES256CBC_KEY", hex2bin("1627298D92C7F9041687217D2A7985C6F368BC232E300B018EC8F8827151493E")); | |
define("AES256CBC_IV", hex2bin("59307F4DEC4EC7D66157972191967500")); | |
function decode($input) { | |
$input = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, AES256CBC_KEY, $input, MCRYPT_MODE_CBC, AES256CBC_IV);; | |
$result = gzuncompress($input); | |
if (substr($result, -1) == "\0") | |
$result = substr($result, 0, -1); | |
return $result; | |
} | |
function encode($input) { | |
if (substr($input, -1) != "\0") | |
$input .= "\0"; | |
$input = gzcompress($input, 9); | |
$result = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, AES256CBC_KEY, $input, MCRYPT_MODE_CBC, AES256CBC_IV); | |
return $result; | |
} | |
if (PHP_SAPI !== 'cli') { | |
echo "only for cli\n"; | |
exit; | |
} | |
if ($argc < 4) { | |
echo "Usage : ".$argv[0]." {encrypt | decrypt} input_file output_file"; | |
exit; | |
} | |
$command = $argv[1]; | |
$input_file = $argv[2]; | |
$output_file = $argv[3]; | |
if ($command == "encrypt") { | |
$input = file_get_contents($input_file); | |
file_put_contents($output_file, encode($input)); | |
} | |
else if ($command == "decrypt") { | |
$input = file_get_contents($input_file); | |
file_put_contents($output_file, decode($input)); | |
} | |
else { | |
echo "Usage : ".$argv[0]." {encrypt | decrypt} input_file output_file"; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment