search

Home  >  Q&A  >  body text

What to use instead of mcrypt_encrypt in php7.1

Now there is such a line of code in the program

    
    $encrypted = mcrypt_encrypt(
        MCRYPT_RIJNDAEL_128, 
        "1234567890123456", 
        "123456", 
        MCRYPT_MODE_CBC,
        "1234567890123456"
    );
    
    echo base64_encode($encrypted);
    
    // 得到的结果为 QEwd/DWmy/4yGncCqBofQQ==
    

But in php7.1.*, the mcrypt_encrypt function is no longer allowed to be used, so I would like to ask you what method should I use to get the same result. Searching on the Internet, some people said to use openssl_encrypt Function replacement, but I still can’t get the correct result after testing it;


    echo openssl_encrypt(
        "123456", 
        "AES-128-CBC", 
        "1234567890123456", 
        null, 
        "1234567890123456"
    );
    
    // 得到的结果为 1jdzWuniG6UMtoa3T6uNLA==

Have you ever encountered such a problem? How did you solve it in the end?

PHPzPHPz2814 days ago1054

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-06-05 11:10:35

    Did you forget base64_encode in the following result

    reply
    0
  • Cancelreply