I am trying to create a function which can encrypt a string. I have the following code but I am getting an error.
$key = "testkey";
// This is the function that does the encryption. Treat it as a black box. Do not edit!
function encrypt($str, $key){
$block = mcrypt_get_block_size('ISO-8859-1', 'ecb');
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB));
}
// call the encrypt function and send it the key and the data to encrypt. Store the returned data in the $dataopt variable.
$dataopt = encrypt($rawstring, $key);
The error is "mcrypt_get_block_size(): Module initialization failed on line on line 41" which is $block = mcrypt_get_block_size('ISO-8859-1', 'ecb');
Any ideas?