Skip to content

Instantly share code, notes, and snippets.

@z2z
Created April 27, 2011 13:46
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 z2z/944269 to your computer and use it in GitHub Desktop.
Save z2z/944269 to your computer and use it in GitHub Desktop.
<?php
header("Cache-Control: no-cache");
?>
<form name="input" action="" method="get">
AES ENC: <input type="text" name="enc" />
<input type="submit" value="Submit" />
</form>
<?php
$message = urldecode(utf8_encode($_GET['enc']));
$pwd = 'aaafffaa12345678';
echo 'Test result: ';
echo $message = getDecrypt($message, $pwd);
$messages = explode('/', $message);
$user_id = $messages['0'];
$period = $messages['1'];
$current_time = current_millis();
//300000 - 5 mins
//60000 - 1min
if($current_time - $period >= 300000){
print('<br><br>'.$user_id .', timed out!');
}else{
print('<br><br>Welcome '. $user_id);
}
echo '<br> Key Time at '.datetimems($period).' TS:('.$period.')';
echo '<br> Current Time '.datetimems($current_time).' TS:('.$current_time.')';
echo '<hr><br>';
echo '<strong>Encrption of User ID & TS : 9028019/'.$current_time.'</strong><br><hr>';
echo 'encrypted : '.$enc = getEncrypt('9028019/'.$current_time,$pwd);
echo '<br><a href="test.php?enc='.urlencode($enc).'">TEST</a></h3><br>';
echo '<hr><br><strong>Decryption of above encrypted string</strong><br><hr>';
echo 'decrypted : '.getDecrypt($enc, $pwd);
function datetimems($ts){
$mil = $ts;
$seconds = $mil / 1000;
return $datetime = date("Y-m-d H:i:s", $seconds);
}
function getDecrypt($string, $key) {
return mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
$key,
base64_decode($string),
MCRYPT_MODE_ECB
);
}
// resturn encrpted string
function getEncrypt($sStr, $sKey) {
return base64_encode(
mcrypt_encrypt(
MCRYPT_RIJNDAEL_128,
$sKey,
$sStr,
MCRYPT_MODE_ECB
)
);
}
// return our current unix time in millis
function current_millis($e = 7) {
list($usec, $sec) = explode(" ", microtime());
return round(((float)$usec + (float)$sec) * 1000);
//return round(( bcadd($usec, $sec, $e) ) * 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment