<?php
function decryptData($value){
$key = "ICS2015";
$crypttext = base64_decode($value);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}
function encryptData($value)
{
$key = "ICS2015";
$text = $value;
// getting the size of the IV (Initialization Vector) belonging to a specific cipher / mode combination
// Accept two params
// 1: cipher (MCPYPT_ciphername constraint or the name of algorithms string)
// 2: mode (MCPYPT_MODE_modename constraint or one of the following string - ecb, cbc, cfb, ofb, nofb or stream )
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
// Create an initialization vector(IV) from RANDOM source
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
// Encrypt plaintext with given params
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
return base64_encode($crypttext);
}
$data = 'testdata';
$encData = encryptData($data);
$decData = decryptData($encData);
echo "$data : " + $data + "\r\n";
echo "$encData : " + $encData + "\r\n";
echo "$decData : " + $decData + "\r\n";
?>
preferences:
76.61 ms | 402 KiB | 5 Q