@ 2016-01-12T12:58:37Z <?php
final class Encryption
{
// The key
const KEY = '36F3D40A7A41A827968BE75A87D60950';
/**
* Encrypt a string
*
* @access public
* @static
* @param string $string
* @return string
*/
public static function encrypt($string)
{
return mcrypt_encrypt(MCRYPT_RIJNDAEL_256, self::getMySQLKey(self::KEY), self::getPaddedString($string), MCRYPT_MODE_CBC, self::KEY);
}
/**
* Decrypt a string
*
* @access public
* @static
* @param string $string
* @return string
*/
public static function decrypt($string)
{
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::getMySQLKey(self::KEY), $string, MCRYPT_MODE_CBC, self::KEY), "\x00..\x10");
}
/**
* Get MySQL key
*
* @access public
* @static
* @param string $key
* @return string
*/
public static function getMySQLKey($key)
{
$key .= $key;
// The new key
$new_key = str_repeat(chr(0), 32);
// Iterate over the key and XOR
for ($i = 0, $l = strlen($key); $i < $l; ++$i)
{
$new_key[$i % 32] = $new_key[$i % 32] ^ $key[$i];
}
// Return the new key
return $new_key;
}
/**
* Get padded string
*
* @access public
* @static
* @param string $string
* @return string
*/
public static function getPaddedString($string)
{
return str_pad($string, (16 * (floor(strlen($string) / 16) + 1)), chr(16 - (strlen($string) % 16)));
}
}
echo base64_encode(Encryption::encrypt('michael@example.com'));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught Error: Call to undefined function mcrypt_encrypt() in /in/K1GZm:18
Stack trace:
#0 /in/K1GZm(75): Encryption::encrypt('michael@example...')
#1 {main}
thrown in /in/K1GZm on line 18
Process exited with code 255 . Output for 5.5.0 - 5.5.38 , 5.6.0 - 5.6.38 Fatal error: Call to undefined function mcrypt_encrypt() in /in/K1GZm on line 18
Process exited with code 255 . preferences:dark mode live preview
271.83 ms | 402 KiB | 322 Q