17771258
V2EX  ›  PHP

php7.1 mcrypt_encrypt 用什么替代

  •  
  •   17771258 · Jun 1, 2017 · 6675 views
    This topic created in 3441 days ago, the information mentioned may be changed or developed.
    现在程序中有这样一行代码

    ``` php

    $encrypted = mcrypt_encrypt(
    MCRYPT_RIJNDAEL_128,
    "1234567890123456",
    "123456",
    MCRYPT_MODE_CBC,
    "1234567890123456"
    );

    echo base64_encode($encrypted);

    // 得到的结果为 QEwd/DWmy/4yGncCqBofQQ==

    ```
    但是在 `php7.1.*` 中 `mcrypt_encrypt` 函数已经不允许使用,所以想请问各位我应该用什么方法得到同样的结果,在网上搜索有人说用 `openssl_encrypt` 函数替代,但是我测试了一圈还是不能得到正确的结果;

    ``` php

    echo openssl_encrypt(
    "123456",
    "AES-128-CBC",
    "1234567890123456",
    null,
    "1234567890123456"
    );

    // 得到的结果为 1jdzWuniG6UMtoa3T6uNLA==

    ```
    各位有遇到过这样的问题吗,最后是怎么解决的。
    8 replies  •  2017-06-07 21:21:49 +08:00
    justanding
    justanding
    Jun 1, 2017
    1
    用 openssl_encrypt
    eoo
    eoo
    Jun 1, 2017 via Android
    2
    官方手册
    Vonex
    Vonex
    Jun 1, 2017
    3
    hash('sha512','xxx')不好吗
    chenney
    chenney
    Jun 2, 2017
    6
    null 改成 OPENSSL_ZERO_PADDING 试试
    components
    components
    Jun 2, 2017
    7
    http://php.net/manual/en/migration71.deprecated.php

    The mcrypt extension has been abandonware for nearly a decade now, and was also fairly complex to use. It has therefore been deprecated in favour of OpenSSL, where it will be removed from the core and into PECL in PHP 7.2.
    iyaozhen
    iyaozhen
    Jun 7, 2017
    8
    但貌似有个问题 openssl_decrypt 不支持 PKCS5
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3481 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 04:19 · PVG 12:19 · LAX 20:19 · JFK 23:19
    ♥ Do have faith in what you're doing.