mcrypt is deprecated, what is the alternative?

前端 未结 10 2334
青春惊慌失措
青春惊慌失措 2020-11-22 08:05

The mcrypt-extension is deprecated will be removed in PHP 7.2 according to the comment posted here. So I am looking for an alternative way to encrypt passwords.

Righ

10条回答
  •  一生所求
    2020-11-22 08:41

    Pure-PHP implementation of Rijndael exists with phpseclib available as composer package and works on PHP 7.3 (tested by me).

    There's a page on the phpseclib docs, which generates sample code after you input the basic variables (cipher, mode, key size, bit size). It outputs the following for Rijndael, ECB, 256, 256:

    a code with mycrypt

    $decoded = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, ENCRYPT_KEY, $term, MCRYPT_MODE_ECB);
    

    works like this with the library

    $rijndael = new \phpseclib\Crypt\Rijndael(\phpseclib\Crypt\Rijndael::MODE_ECB);
    $rijndael->setKey(ENCRYPT_KEY);
    $rijndael->setKeyLength(256);
    $rijndael->disablePadding();
    $rijndael->setBlockLength(256);
    
    $decoded = $rijndael->decrypt($term);
    

    * $term was base64_decoded

提交回复
热议问题