Skip to content

Instantly share code, notes, and snippets.

@Stricted
Last active February 16, 2017 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stricted/f541b7cb2e79d0242091 to your computer and use it in GitHub Desktop.
Save Stricted/f541b7cb2e79d0242091 to your computer and use it in GitHub Desktop.
<?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