17771258
V2EX  ›  PHP

php7.1 mcrypt_encrypt 用什么替代

  •  
  •   17771258 · Jun 1, 2017 · 6319 views
    This topic created in 3295 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
        1
    justanding  
       Jun 1, 2017
    用 openssl_encrypt
    eoo
        2
    eoo  
       Jun 1, 2017 via Android
    官方手册
    Vonex
        3
    Vonex  
       Jun 1, 2017
    hash('sha512','xxx')不好吗
    m939594960
        5
    m939594960  
       Jun 2, 2017
    chenney
        6
    chenney  
       Jun 2, 2017
    null 改成 OPENSSL_ZERO_PADDING 试试
    components
        7
    components  
       Jun 2, 2017
    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
        8
    iyaozhen  
       Jun 7, 2017
    但貌似有个问题 openssl_decrypt 不支持 PKCS5
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1547 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    ♥ Do have faith in what you're doing.