Matti Kiviharju
Matti Kiviharju

Reputation: 459

I do not get a mcrypt functions to work in PHP 7

I do not get a functions below to work PHP 7:

/*
 * blowfish encrypt function
 * @params
 * $key
 * $plain_text
 */
function encrypt_data($key, $plain_text) {
  $plain_text = trim($plain_text);
  $iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_BLOWFISH,MCRYPT_MODE_CFB));
  $c_t = mcrypt_encrypt (MCRYPT_BLOWFISH, $key, $plain_text, MCRYPT_MODE_CFB, $iv);
  return base64_encode($c_t); 
}

/*
 * blowfish decrypt function
 * @params
 * $key
 * $c_t
 */
function decrypt_data($key, $c_t) {
  $c_t = base64_decode($c_t);
  $iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_BLOWFISH,MCRYPT_MODE_CFB));
  $p_t = mcrypt_decrypt (MCRYPT_BLOWFISH, $key, $c_t, MCRYPT_MODE_CFB, $iv);
  return trim($p_t);
}

I will get no PHP warnings.

I think this the line, $iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_BLOWFISH,MCRYPT_MODE_CFB));, is incorrectly made.

What to do?

Upvotes: 0

Views: 158

Answers (1)

Michael B.
Michael B.

Reputation: 995

Could it be that you use PHP7.2?

mcrypt isn't supported anymore in PHP7.2, was deprecated in 7.1 and finally removed.

libmcrypt, on which it is based, had an abandoned upstream support since 2007! So it was time to get rid of it.

Upvotes: 1

Related Questions