@ 2015-11-27T12:54:34Z <?php
function csidAES($strMessage, $strKey, $strOperation = 'encrypt') {
/**
* csidAES
* Provides encryption (default) and decryption suitable for use with the CSID SMS API.
* @license CSID Partner Restricted
* @param string $strMessage The message (cleartext or cyphertext) on which to operate.
* @param string $strKey The agreed-upon encryption key.
* @param string $strOperation OPTIONAL: One of 'encrypt' or 'decrypt' (default:
* 'encrypt').
* @return string|bool Returns the resulting text, or FALSE on failure.
*/
echo $strMessage . ' is input to : ' . $strOperation . "<br/>";
switch ($strOperation){
case 'encrypt':
echo "md5 of '".$strMessage . "' is : " . md5($strMessage) . "<br/>";
$AES_KEY = substr(md5($strKey), 0, 16);
$iv = mcrypt_create_iv(16, MCRYPT_RAND);
echo $iv . " - random generated IV<br/>";
//Perform encryption
$ctext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $AES_KEY, $strMessage, MCRYPT_MODE_CBC, $iv);
echo $ctext . " - encrypted<br/>";
$ctext = $iv.$ctext;
echo $ctext . " - iv.ctext<br/>";
// Base64-encode, then urlencode the ciphertext
$ctext = urlencode(base64_encode($ctext));
echo $ctext . " - url encoded ctext<br/>";
return $ctext;
break;
case 'decrypt':
$key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
echo $key_size . " - key_size<br/>";
$AES_KEY = substr(md5($strKey), 0, 16);
echo $AES_KEY . " - AES_KEY<br/>";
$iv = mcrypt_create_iv(16, MCRYPT_RAND);
echo $iv . " - random generated IV<br/>";
//Perform a base64_decode.
$ctext = base64_decode($strMessage);
echo $ctext . " - decoded input<br/>";
$thIV = substr($ctext,0,16);
echo "thIV : " . $thIV . "<br/>";
$thingForDecoding = substr($ctext,16);
echo "thingForDecoding : " . $thingForDecoding . "<br/>";
//NOTE: No need to urldecode; the API server did it for us.
//Perform decryption
$ptext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $AES_KEY, $ctext,
MCRYPT_MODE_CBC, $iv);
echo $ptext . " - decrypted<br/>";
$ptext = substr($ptext,16);
echo $ptext . " - a substring of it";
$final = str_replace(chr(0),"",$ptext);
echo $final . " - final";
return $final;//str_replace(chr(0),"",$ptext);
break;
default:
return false;
break;
}
}
$csIDn = new ReflectionFunction('csidAES');
$originalText = 'Mirko Atanasov';
$encrypted = $csIDn->invoke($originalText , 'g3rWsiNm7Gwh9qMc','encrypt');
echo $encrypted;
echo "<br/><br/> and now the decryption<br/><br/>";
$decrypted = $csIDn->invoke($encrypted, 'g3rWsiNm7Gwh9qMc','decrypt');
echo $decrypted;
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks Mirko Atanasov is input to : encrypt<br/>md5 of 'Mirko Atanasov' is : 429d6d7e5cd4b233dcb12a1fa9a05d45<br/>
Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/3DPMt:19
Stack trace:
#0 [internal function]: csidAES('Mirko Atanasov', 'g3rWsiNm7Gwh9qM...', 'encrypt')
#1 /in/3DPMt(68): ReflectionFunction->invoke('Mirko Atanasov', 'g3rWsiNm7Gwh9qM...', 'encrypt')
#2 {main}
thrown in /in/3DPMt on line 19
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
48.09 ms | 401 KiB | 8 Q