2

I update my server from 5.45 to 7.1 after that I am getting an error. I am getting the issue in decryptIt function.

function encryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
    return( $qEncoded );
}

function decryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qDecoded      = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
    return( $qDecoded );
}

I am encrypting the id using below code so that I can display the URL something like this uYxnJrS3aLv0JbJFLnnmW4TRRpF6%2FYB0JD6LUhPYu0U%3D#

$p_id=10;
$encrypted_user_id1 = encryptIt($p_id);
$p_user_id1=urlencode($encrypted_user_id1);

And decrepting it so that I will get the $p_id=10 on my page

$decrypted_p_id = decryptIt($p_id);

But I am getting error now

Deprecated: Function mcrypt_decrypt() is deprecated

Would you help me out in this?

Naren Verma
  • 2,205
  • 5
  • 38
  • 95
  • PHP has made this function, `mcrypt_decrypt`, deprecated since PHP 7.1.0. This is their official message: "Warning This function has been DEPRECATED as of PHP 7.1.0. Relying on this function is highly discouraged." – Sam Sep 27 '17 at 01:27
  • 1
    I thought the error was quite clear. The function is deprecated, don't use it. – Luke Joshua Park Sep 27 '17 at 01:27
  • I suggest using an already existing project, [AES encryption](https://aesencryption.net) is a great project – Sam Sep 27 '17 at 01:30
  • @LukePark, You are right, the error was quite clear. Is there any other option to encrypt the Id in the URL and decrypt it on the page? – Naren Verma Sep 27 '17 at 01:54
  • Use `openssl_decrypt` instead – Luke Joshua Park Sep 27 '17 at 01:57
  • @LukePark, Ok I will try this. – Naren Verma Sep 27 '17 at 01:59
  • @NarendraVerma - It was news to me too :s, ive just gone through all my answers which used the function and updated them, if you want an example here is one https://stackoverflow.com/questions/10536664/looking-for-simple-php-multi-way-encryption-method/10536780#10536780 – Lawrence Cherone Sep 27 '17 at 02:17
  • @LawrenceCherone, Thanks, I tested and working. I just need to know for a more secure form where I will get the PrivateKey and SecretKey? – Naren Verma Sep 27 '17 at 02:27
  • If it helped ill be waiting for an upvote `;p`.. kidding, The `PrivateKey` is like your `md5($cryptKey)` but you pass it as a param, or change it in the function construct. `SecretKey` is the same as your double `md5(md5($cryptKey))`. It's not more or less secure, as CBC is CBC. – Lawrence Cherone Sep 27 '17 at 02:37
  • Yes, done for an upvote, Thanks for your help – Naren Verma Sep 27 '17 at 02:42
  • 1
    Thanks, if you're looking for something more secure/flexible have a look at https://github.com/phpseclib/phpseclib – Lawrence Cherone Sep 27 '17 at 02:49
  • @LawrenceCherone, Thanks for the reply. I just want to use in the URL and sometime in password – Naren Verma Sep 27 '17 at 05:24
  • I posted a full answer for PHP7.3 on the linked question https://stackoverflow.com/a/53937314/243782 – Pentium10 Dec 26 '18 at 21:29

0 Answers0