【问题标题】:Replace Mcrypt with OpenSSL - is that possible用 OpenSSL 替换 Mcrypt - 这可能吗
【发布时间】:2020-05-17 06:40:04
【问题描述】:

目前我们在我们的系统上有一个 mcrypt 实现来加密我们的 PHP 应用程序中的一些 Id。 但是 Mcrypt 现在已被弃用,我必须更换它。

很遗憾,我无法转换所有保存的信息。 解密就够了。

这是我使用的两个函数:

self::$key = '123456';

public static function encrypt($plaintext)
{
    $td = mcrypt_module_open('cast-256', '', 'ecb', '');
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, self::$key, $iv);

    $encrypted_data = mcrypt_generic($td, $plaintext);

    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);

    $encoded_64 = base64_encode($encrypted_data);

    return trim($encoded_64);
}

public static function decrypt($crypttext)
{
    $decoded_64 = base64_decode($crypttext);

    $td = mcrypt_module_open('cast-256', '', 'ecb', '');
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, self::$key, $iv);

    $decrypted_data = mdecrypt_generic($td, $decoded_64);

    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);

    return trim($decrypted_data);
}

【问题讨论】:

    标签: php mcrypt


    【解决方案1】:

    嗯? PHP 支持 OpenSSL ...https://www.php.net/manual/en/book.openssl.php

    “所以,当然是的。”您可以使用 mcrypt 解密所有现有信息,然后使用 OpenSSL 或您选择的其他密码算法对其进行加密。

    现在,我要记住,OpenSSL 是围绕“公钥和私钥”的概念设计的。所以,如果你走那条路,你应该尝试利用它。实际上有很多密码算法可以在现代 PHP 中使用...https://www.php.net/manual/en/function.crypt.php

    【讨论】:

      猜你喜欢
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 2018-08-29
      • 2019-07-23
      • 2017-06-23
      • 2017-10-15
      • 2020-05-16
      相关资源
      最近更新 更多